-
Notifications
You must be signed in to change notification settings - Fork 5
Create RESTful server
Bruno Oliveira edited this page May 20, 2015
·
2 revisions
With EasyFast PHP is very easy to create a RESTful server, see some examples below.
use EasyFast\Http\Restful;
$rest = new Restful();
$rest->server('POST', 'url-request/user/:id', function ($id) {
// performs its task
Restful::response('message' => "The return on json - $id " | 'index' => 2, 203);
});
The above example is simple, we expect a POST request to the URL "url-request/user/:id" and we get the parameter ":id" parameter returning as the callback function. And inside the callback function we perform all our tasks, query, etc ... In this example only one return JSON and HTTP 203 status.
We could only return a message (string, xml, etc.):
Restful::response('String message.', 200);
It is important that the .htaccess file is correctly set up, navigate to the initial configuration session and see if your configuration is correct.