Skip to content

Grokem · https://www.grokem.com/programming/apis-integrations/rest/http-status-codes-reference

RESTReference

HTTP status codes: the ones you will actually meet

Every status code a typical web application or API returns, grouped by what the client should do next, with the mistakes that cause each one.

Grokem Editorial

Editorial desk

Published
  • 5 min read

A status code is a three-digit number that says how a request went. The first digit gives the class, and is often all you need to know what to do next.

Class Meaning The client should
1xx Informational Wait for the final response
2xx Success Carry on
3xx Redirection Follow the new address, or use a cached copy
4xx The request was wrong Fix the request. Repeating it unchanged will not help
5xx The server failed Retry later, with backoff, if the operation is safe to repeat

2xx: it worked

Code Name Meaning and typical use
200 OK The request succeeded, and the response has the result. The default for a successful GET
201 Created A new resource was made. The Location header should point to it. The usual answer to a POST that creates
202 Accepted Received and will be processed later. Use for work that continues in the background
204 No Content Success with nothing to return. Common for DELETE and some updates
206 Partial Content Part of a resource, in answer to a range request (resumable downloads, video)

3xx: look elsewhere

Code Name Meaning and typical use
301 Moved Permanently The address has changed for good. Browsers and search engines update. The method may change to GET
302 Found A temporary move. Historically ambiguous about the method
303 See Other After a POST, go and GET another page (the post/redirect/get pattern)
304 Not Modified Your cached copy is still valid. Sent in answer to a conditional request (If-None-Match, If-Modified-Since)
307 Temporary Redirect A temporary move that keeps the method and body
308 Permanent Redirect A permanent move that keeps the method and body

4xx: the request has a problem

Code Name What it usually means What to do
400 Bad Request Malformed syntax, an invalid body or parameters Fix the request
401 Unauthorized You are not authenticated, or the credentials are wrong or expired Send valid credentials. The name is misleading: it is about authentication
403 Forbidden Authenticated, but not allowed to do this Ask for permission. Re-sending the same credentials will not help
404 Not Found Nothing at this address (or the server hides that it exists) Check the URL and the id
405 Method Not Allowed The resource does not support this method. The Allow header lists the ones it does Use an allowed method
406 Not Acceptable The server cannot produce a response in a format you accept Adjust the Accept header
408 Request Timeout The server gave up waiting for the request Try again
409 Conflict The request conflicts with the current state, such as an edit clash or a duplicate Fetch the current state and resolve
410 Gone Existed once and was removed on purpose Stop using it
412 Precondition Failed A condition such as If-Match was not met, often a sign someone else changed it Re-fetch and retry
413 Content Too Large The body is bigger than the server accepts Send less, or in parts
415 Unsupported Media Type The body's format is not accepted Check the Content-Type header
422 Unprocessable Content The syntax is fine but the content fails validation Fix the fields named in the error
429 Too Many Requests You are being rate-limited. Retry-After may say when to return Slow down and wait

5xx: the server has a problem

Code Name What it usually means What to do
500 Internal Server Error An unhandled error in the server's code Retry later; report it if it persists
501 Not Implemented The server does not support this feature or method Do not retry
502 Bad Gateway A proxy or gateway received an invalid answer from the server behind it Retry later
503 Service Unavailable Overloaded or down for maintenance. Retry-After may be sent Retry with backoff
504 Gateway Timeout A proxy waited too long for the server behind it Retry later; the work may have been done

Habits that save time

  • 401 versus 403. If you do not know who the caller is, return 401. If you know and they are not permitted, return 403.
  • Use the specific code. A 422 for failed validation and a 404 for a missing item let the caller react correctly. Returning 200 with {"error": ...} hides failure from every tool that reads status codes.
  • Retry only what is safe. GET and idempotent requests can be retried after 429 and 5xx errors. A blind retry of a POST can create duplicates unless the API supports an idempotency key.
  • Read the body and the headers. The code gives the category. The body usually carries the details, and headers such as Location, Retry-After and Allow carry instructions.

From Grokem: https://www.grokem.com/programming/apis-integrations/rest/http-status-codes-reference

How did this strike you?

Be the first to react – it is anonymous.

Comments

No comments yet. Share what worked for you, or ask a question.

Keep going

All in topic
RESTBest practices

A REST API design checklist

Resources, methods, status codes, errors, pagination, versioning and security: the decisions that make an HTTP API predictable for the people who build on it.

Grokem Editorial3 min

Choose what we may use. You can change this at any time with “Privacy choices” at the foot of every page. Details are in the Cookie policy and the Privacy policy.

Strictly necessary

Remembers your theme, the lessons you marked as done and this choice. It stays on your device, tracks nothing and cannot be switched off.

Always on
What exactly is collected, and why

Grokem’s own counts

Collects
The pages you open and how long you stay, how far you scroll, where you came from, your device type, browser, screen size, language and time zone. Your IP address is turned into a code that changes every day; it is never stored as it is.
Why
To see how long lessons are read and where readers leave. Not shared with anyone.
Stored
A random visitor ID, a visit ID and the time of your last page view in your browser’s storage (gr_vid, gr_sid, gr_last). No name or email is attached.