🔥 Quick Tip: Using HTTP Status Codes with Laravel API Resources

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.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.