Understanding HTTP Status Codes

matt
Matthew Gros · Nov 1, 2025

TLDR

2xx success, 3xx redirect, 4xx client error, 5xx server error. Use specific codes, not just 200 and 500.

Understanding HTTP Status Codes

Status Codes Tell a Story

The right code helps clients handle responses correctly.

2xx - Success

200 OK - Request succeeded
201 Created - Resource created (POST)
204 No Content - Success, nothing to return (DELETE)
return response()->json($user, 200);
return response()->json($newUser, 201);
return response()->noContent(); // 204

3xx - Redirection

301 Moved Permanently - URL changed forever (SEO)
302 Found - Temporary redirect
304 Not Modified - Use cached version

4xx - Client Errors

400 Bad Request - Malformed request
401 Unauthorized - Not authenticated
403 Forbidden - Authenticated but not allowed
404 Not Found - Resource doesn't exist
405 Method Not Allowed - Wrong HTTP method
409 Conflict - Conflicting with current state
422 Unprocessable Entity - Validation failed
429 Too Many Requests - Rate limited
// Common usage
abort(404);
abort(403, 'You cannot edit this post');

return response()->json([
    'message' => 'Validation failed',
    'errors' => $validator->errors()
], 422);

5xx - Server Errors

500 Internal Server Error - Generic server error
502 Bad Gateway - Upstream server error
503 Service Unavailable - Server overloaded/maintenance
504 Gateway Timeout - Upstream timeout

Quick Reference

| Action | Success | Error | |--------|---------|-------| | GET item | 200 | 404 | | GET list | 200 | - | | POST create | 201 | 422 | | PUT/PATCH update | 200 | 404, 422 | | DELETE | 204 | 404 |

About the Author

matt

I build and ship automation-driven products using Laravel and modern frontend stacks (Vue/React), with a focus on scalability, measurable outcomes, and tight user experience. I’m based in Toronto, have 13+ years in PHP, and I also hold a pilot’s license. I enjoy working on new tech projects and generally exploring new technology.