What is the purpose of HTTP Status Code?

Technology CommunityCategory: API DesignWhat is the purpose of HTTP Status Code?
VietMX Staff asked 3 years ago

HTTP Status code are standard codes and refers to predefined status of task done at server. For example, HTTP Status 404 states that requested resource is not present on server.

Consider following status codes:

  • 200 – OK, shows success.
  • 201 – CREATED, when a resource is successful created using POST or PUT request. Return link to newly created resource using location header.
  • 304 – NOT MODIFIED, used to reduce network bandwidth usage in case of conditional GET requests. Response body should be empty. Headers should have date, location etc.
  • 400 – BAD REQUEST, states that invalid input is provided e.g. validation error, missing data.
  • 401 – FORBIDDEN, states that user is not having access to method being used for example, delete access without admin rights.
  • 404 – NOT FOUND, states that method is not available.
  • 409 – CONFLICT, states conflict situation while executing the method for example, adding duplicate entry.
  • 500 – INTERNAL SERVER ERROR, states that server has thrown some exception while executing the method.