Is a minor silex application showcasing the of how to handle request and responses with an general error handler.
$ composer install
$ php -S 127.0.0.1:1337
Example are using httpie for issuing requests. You can use curl if you remember its syntax for I cannot.
$ http GET 127.0.0.1:1337
HTTP/1.1 405 Method Not Allowed
Allow: POST
Cache-Control: no-cache
Connection: close
Content-Type: application/json
Date: Wed, 14 Oct 2015 15:25:41 GMT
Host: 127.0.0.1:1337
X-Powered-By: PHP/5.5.9-1ubuntu4.13
{
"message": "No route found for \"GET /\": Method Not Allowed (Allow: POST)"
}
$ http POST 127.0.0.1:1337
HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Connection: close
Content-Type: application/json
Date: Wed, 14 Oct 2015 15:26:20 GMT
Host: localhost:1337
X-Powered-By: PHP/5.5.9-1ubuntu4.13
{
"message": "Data parameter required"
}
$ http POST 127.0.0.1:1337 data="hello world" --form
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: close
Content-Type: application/json
Date: Wed, 14 Oct 2015 15:24:59 GMT
Host: localhost:1337
X-Powered-By: PHP/5.5.9-1ubuntu4.13
{
"message": "hello world"
}