Showing posts with label "HTTP Codes". Show all posts
Showing posts with label "HTTP Codes". Show all posts

Wednesday, May 31, 2017

HTTP Status Codes in Restful API


Here is a list of most common HTTP codes that are used in Restful API designs:

  • 200 - OK
  • 400 - Bad Request (Client Error) - a json with error and more details of the errors.
  • 401 - Unauthorized
  • 500 - Internal Server Error - a json with an error may return to the client without details to avoid security risk

  • 202 (Accepted) - when no response returns, e.g. asyncronous processing is used
  • 401 (Unauthorized) - when there is a problem with the client’s credentials
  • 403 (Forbidden) - forbid access regardless of authorization state
  • 404 (Not Found) - when a client’s URI cannot be mapped to a resource

Sample of 400 response:


{
  "errors": [
    {
      "error": {
        "code": "100000400",
        "field": "transactionId",
        "message": "transaction is required."
        "link": "https://url link to a page with explanation"
      }
    }
  ]
}


Sample of 500 response:


{
  "error": {
    "code": "100000500",
    "reference": "3344c2e4-d54c-5caf-a4ea-c342cb4cccad",
    "message": "Server error."
  }
}
















































HTTP Status Codes Usage Examples

APIStatus Codes
Twitter200, 304, 400, 401, 403, 404, 406, 410, 420, 422, 429, 500, 502, 503, 504
Stripe200, 400, 401, 402, 404, 429, 500, 502, 503, 504
Github200, 400, 422, 301, 302, 304, 307, 401, 403
Pagerduty200, 201, 204, 400, 401, 403, 404, 408, 500
NewRelic Plugins200, 400, 403, 404, 405, 413, 500, 502, 503, 503
Etsy200, 201, 400, 403, 404, 500, 503
Dropbox200, 400, 401, 403, 404, 405, 429, 503, 507
Spotify200, 201, 204, 304, 400, 401, 403, 404, 429, 500, 502, 503
Google Cloud200, 301, 304, 307, 308, 400, 401, 403, 404, 405, 409, 411, 412, 416, 429, 500, 501, 503
HipChat200, 201, 202, 400, 401, 403, 404, 405, 429, 500, 503
Telegram200, 303, 400, 401, 403, 404, 420, 500
Pocket200, 400, 401, 403, 503
Uber200, 201, 400, 401, 403, 404, 406, 409, 422, 429, 500