Tutorials / Tech blog / Geek Zone

Latest Posts

Sunday, May 28, 2017

HTTP Status Codes :: 200 vs 202 vs 204

With the world embracing microservices architecture, we as developers are now heavily involved in designing / consuming API's. One of the most important aspect of such webservices design is to have the right HTTP status codes mapped. This enables the consumer (of the webservice) to get more insight around the response received.

One of the dilemma I had encountered was to figure out the right 2xx Success HTTP status code for Update (HTTP PUT) / Delete (HTTP DELETE) scenarios. Had narrowed down on 200 / 202 / 204 Http Status codes.



Lets go through the official definition for these status codes first to help us understand better.

HTTP 200 OK

The request has been fulfilled and resulted in a new resource being created.

HTTP 202 Accepted

The request has been accepted for processing, but the processing has not been completed.

HTTP 204 No Content

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated meta-information.


Based on the above definitions, a successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity response body. 


3 comments:

  1. Hi
    As I read, Http code 201 is Resource is created. And 200 is Okay.
    but as per you blog 200 is Resource is created.
    So what is diff. between 200 and 201 ?

    ReplyDelete
    Replies
    1. For the PUT method, 200 means "Okay, resource updated". - Resource already existed
      201 for PUT methid means "Okay, resource created". - Resource did not already exist

      Delete
  2. For the PUT method, 200 means "Okay, resource updated". - Resource already existed
    201 for PUT methid means "Okay, resource created". - Resource did not already exist

    ReplyDelete