Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
General REST API HTTP Status Codes

Reference: RFC 2616 - HTTP Status Code Definitions

General

  • 400 BAD REQUEST: The request was invalid or cannot be otherwise served. An accompanying error message will explain further. For security reasons, requests without authentication are considered invalid and will yield this response.
  • 401 UNAUTHORIZED: The authentication credentials are missing, or if supplied are not valid or not sufficient to access the resource.
  • 403 FORBIDDEN: The request has been refused. See the accompanying message for the specific reason (most likely for exceeding rate limit).
  • 404 NOT FOUND: The URI requested is invalid or the resource requested does not exists.
  • 406 NOT ACCEPTABLE: The request specified an invalid format.
  • 410 GONE: This resource is gone. Used to indicate that an API endpoint has been turned off.
  • 429 TOO MANY REQUESTS: Returned when a request cannot be served due to the application’s rate limit having been exhausted for the resource.
  • 500 INTERNAL SERVER ERROR: Something is horribly wrong.
  • 502 BAD GATEWAY: The service is down or being upgraded. Try again later.
  • 503 SERVICE UNAVAILABLE: The service is up, but overloaded with requests. Try again later.
  • 504 GATEWAY TIMEOUT: Servers are up, but the request couldn’t be serviced due to some failure within our stack. Try again later.

HTTP GET

  • 200 OK: The request was successful and the response body contains the representation requested.
  • 302 FOUND: A common redirect response; you can GET the representation at the URI in the Location response header.
  • 304 NOT MODIFIED: There is no new data to return.

HTTP POST or PUT

  • 201 OK: The request was successful, we updated the resource and the response body contains the representation.
  • 202 ACCEPTED: The request has been accepted for further processing, which will be completed sometime later.

HTTP DELETE

  • 202 ACCEPTED: The request has been accepted for further processing, which will be completed sometime later.
  • 204 OK: The request was successful; the resource was deleted.
@naveensnap

This comment has been minimized.

Copy link

@naveensnap naveensnap commented Nov 16, 2017

What is 409 error? It reflects a conflict when using a PUT request but no mention here. How do we handle it?

@ssi-anik

This comment has been minimized.

Copy link

@ssi-anik ssi-anik commented Nov 30, 2017

422 for validation error?

@peterjernei

This comment has been minimized.

Copy link

@peterjernei peterjernei commented Jan 15, 2018

I have 202 returned to GET requests.

My bad, i have set Content-type to the request to JSON. After removing this header parameter i am getting the expected results.

@GuyT07

This comment has been minimized.

Copy link

@GuyT07 GuyT07 commented Feb 13, 2018

201 is "created" and therefore a location to the new resource should be included instead of response body containing the representation.

@d3ep4k

This comment has been minimized.

Copy link

@d3ep4k d3ep4k commented May 4, 2018

Good work. I have added a list with explaination here. https://metamug.com/article/status-codes-for-rest-api.php

@olibre

This comment has been minimized.

Copy link

@olibre olibre commented Oct 25, 2019

Thanks, I have just wrote a longer version: http://olibre.github.io/GreatTips/web/api.html

@Yousha

This comment has been minimized.

Copy link

@Yousha Yousha commented Feb 2, 2020

@QasimWani

This comment has been minimized.

Copy link

@QasimWani QasimWani commented Nov 22, 2020

What is 409 error? It reflects a conflict when using a PUT request but no mention here. How do we handle it?

hey, did u figure out what 409 error represents? Documentation says conflict, but there's no description of it.

@jbrasileiro

This comment has been minimized.

Copy link

@jbrasileiro jbrasileiro commented Mar 25, 2021

404 NOT FOUND is about URI, not about the state of the object in server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment