We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
It is possible to return a desired HTTP status code by throwing an exception, like below:
HTTP
public function configureEndpointBag($endpoint_bag) { $endpoint_bag->create('/') ->addGET('get') ->addPOST('create'); } public function get() { return 'inside get function'; } public function post() { throw new \Fabstract\Component\Http\Exception\StatusCodeException\ForbiddenException(); }
Now doing a HTTP POST
HTTP POST
curl -i -X POST yourdomain.postfix/user -H"Content-Type: application/json"
will result in following:
HTTP/1.1 403 Forbidden Content-Type: application/json {"error_message":"forbidden","status":"failure"}
You can use many of the status code exceptions that come with Fabstract
ForbiddenException will be HTTP 403
HTTP 403
ConflictException will be HTTP 409
HTTP 409
UnauthorizedException will be HTTP 401
HTTP 401
UnprocessableEntityException will be HTTP 422
HTTP 422
etc.
When an unexpected error happens, system will give HTTP 500. You don't have to do anything.
HTTP 500