Hans
Hans
Dec 14, 2017 · 1 min read

With Laravel 5.5 an awesome feature was added to the core: API Resources. If you have not done it already give it a try. As usual it is well explained in the documentation. For our API we needed one feature which is not documented: Custom Status Codes.

If you are like us, be sure to check out http://http.cat

To get something from the API mostly 200 OK is the default status code, which is fine. When a new record is created successful, you want to use 201 Created and for updated records one would exepct a 202 Accepted .

But Laravel API Resources send 200 OK by default. If you want to change the response, try it this way:

Example Controller sending a `202 Accepted` Response

If you don’t use different status codes, give it a try. It is just a basic info, which helps debugging requests a lot.

Scrumpy

Agile Planning, Made Simple

Hans

Written by

Hans

Co-Founder of @_ueberdosis and @heyscrumpy

Scrumpy

Scrumpy

Agile Planning, Made Simple

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade