Octet

What do the common HTTP status codes mean when you call a network API?

Show the answer

Say this first

2xx is success: 200 OK with a body, 201 Created, 204 No Content (success, no body). 4xx is the client's fault: 400 bad request body, 401 not authenticated, 403 authenticated but not allowed, 404 no such resource, 409 conflict such as the object already exists. 5xx is the server's fault: 500 internal error, 503 unavailable. My scripts retry 429 and 503 with backoff, re-authenticate on 401, and never blindly retry other 4xx.

Go deeper

The codes to know cold

CodeMeaningTypical network API cause
200 OKSuccess with a bodyGET returned data
201 CreatedNew resource madePOST or PUT created an object; Location header points to it
204 No ContentSuccess, nothing to returnRESTCONF PUT, PATCH or DELETE that worked
400 Bad RequestMalformed or invalid requestBad JSON, wrong field name, missing module prefix, value out of range
401 UnauthorizedNot authenticatedMissing, wrong or expired token or password
403 ForbiddenAuthenticated, not allowedRead-only account tries a change; RBAC denies it
404 Not FoundNo such resourceWrong URI, typo in the model path, object not configured
405 Method Not AllowedMethod not supported herePUT on a read-only resource
409 ConflictClashes with current statePOST of an object that already exists; datastore locked
415 Unsupported Media TypeServer cannot read the body formatWrong Content-Type
429 Too Many RequestsRate limitedToo many calls; honor Retry-After
500 Internal Server ErrorServer failedBug or crash on the API side
503 Service UnavailableTemporarily downController starting, overloaded or in maintenance

The classes

1xx informational, 2xx success, 3xx redirect (301, 302, 304), 4xx client error, 5xx server error.

RESTCONF specifics (RFC 8040)

Errors come back with a body that holds error-type, error-tag and error-message. For example data-exists and lock-denied both map to 409.

Traps

  • Swapping 401 and 403.
  • Treating every non-200 as failure. 201 and 204 are success.
How did you do?Book 9.1 Traditional Applications