Creating a web service in PHP

后端 未结 7 952
日久生厌
日久生厌 2021-01-06 12:28

I would like to create a web service in PHP which can be consumed by different consumers (Web page, Android device, iOS device).

I come from a Microsoft background s

7条回答
  •  暖寄归人
    2021-01-06 13:05

    I developed a class that is the PHP native SoapServer class' REST equivalent.

    You just include the RestServer.php file and then use it as follows.

    class Hello
    {
      public static function sayHello($name)
      {
        return "Hello, " . $name;
      }
    }
    
    $rest = new RestServer(Hello);
    $rest->handle();
    

    Then you can make calls from another language like this:

    http://myserver.com/path/to/api?method=sayHello&name=World
    

    (Note that it doesn't matter what order the params are provided in the query string. Also, the param key names as well as the method name are case-insensitive.)

    Get it here.

提交回复
热议问题