Get "PHP 8 in a Nuthshell" (Now comes with PHP 8.3)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Response Code Cheat Sheet for Laravel HTTP Client

Laravel’s HTTP client is a wrapper around PHP’s Guzzle HTTP Client library. It provides a fluent interface to communicate with HTTP endpoints. It can be used to make HTTP requests to external APIs or to communicate with your own application.

The client returns a Illuminate\Http\Client\Response object which contains the response from the server. The Response object has several convenient methods to map response codes to meaningful names and to check if the response was successful or not instead of checking the response code manually.

Here’s a handy cheat sheet for the same.

Response Code Method (bool)
200 OK $response->ok()
201 Created $response->created()
202 Accepted $response->accepted()
204 No Content $response->noContent()
301 Moved Permanently $response->movedPermanently()
302 Found $response->found()
400 Bad Request $response->badRequest()
401 Unauthorized $response->unauthorized()
402 Payment Required $response->paymentRequired()
403 Forbidden $response->forbidden()
404 Not Found $response->notFound()
408 Request Timeout $response->requestTimeout()
409 Conflict $response->conflict()
422 Unprocessable Entity $response->unprocessableEntity()
429 Too Many Requests $response->tooManyRequests()
500 Internal Server Error $response->serverError()
Learn the fundamentals of PHP 8 (including 8.1, 8.2, and 8.3), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

Like this article? Consider leaving a

Tip

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?