CakeDC / cakephp-api

API Plugin for CakePHP
Other
61 stars 33 forks source link

Cannot set response status code #46

Closed birdy247 closed 6 years ago

birdy247 commented 6 years ago

I have tried setting the response code to something other than a 200.

What I tried:

In an Action

$response = $this->getService()->getResponse(); $this->getService()->setResponse($response->withStatus(404));

The response is still always a 200

skie commented 6 years ago

Seems, you are using JsendRenderer. Jsend by specification suppose to return always 200 response code.

birdy247 commented 6 years ago

@skie thanks, so what is the correct way to set the status to fail within an action?

skie commented 6 years ago

You can switch to Json renderer or create custom renderer.

birdy247 commented 6 years ago

Hi @skie Thanks. We like JSend. I noticed there is a 200 response code with a status of fail. I was wondering if this could be configured from a action. https://labs.omniti.com/labs/jsend

Thanks

skie commented 6 years ago

Like I said you should be able to overload Jsend class and add needed functionality.