thephpleague / route

Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.
http://route.thephpleague.com
MIT License
651 stars 126 forks source link

Possible to set status code when using JSON strategy? #267

Closed zkwbbr closed 4 years ago

zkwbbr commented 4 years ago

According to the JSON Strategy doc, we can

return an array or object, and a JSON response will be built for you.

This is convenient but when using this, is it possible to set the HTTP status code without the need to manually build/return an ResponseInterface response?

philipobenito commented 4 years ago

Yeah, just return a response object, being able to return an array is just convenience

Sent from ProtonMail mobile

-------- Original Message -------- On 1 Feb 2020, 20:27, zkwbbr wrote:

According to the JSON Strategy doc, we can

return an array or object, and a JSON response will be built for you.

This is convenient but when using this, is it possible to set the HTTP status code without the need to manually build/return an ResponseInterface response?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

zkwbbr commented 4 years ago

@philipobenito Alright so basically the array return convenience method is there for GET methods with 200 status only. Anything else must be done the usual way with a proper ResponseInterface object.

philipobenito commented 4 years ago

Correct, yes. What I tend to do is build a response factory that can create the different responses I need with hypermedia etc when required.

Sent from ProtonMail mobile

-------- Original Message -------- On 2 Feb 2020, 06:20, zkwbbr wrote:

@philipobenito Alright so basically the array return convenience method is there for GET methods with 200 status only. Anything else must be done the usual way with a proper ResponseInterface object.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

zkwbbr commented 4 years ago

@philipobenito Got it thanks!