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() |
Like this article?
Buy me a coffee👋 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.