Skip to main content

HTTP Response for POST Request

Suppose we're handling requests from client and needs to set response with http status code.

In this case, some questions like which should I return for POST request arise. To clarify this, I'm leaving this post as a record referring to RFC 9110: HTTP Semantics.


Options for status code for successful POST request

There're some options mainly:

  • 200 OK : The request succeeded. The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is heuristically cacheable by default.
  • 201 Created : The request succeeded, and a new resource was created as a result. The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.
  • 204 No Content : There is no content to send for this request, but the headers may be useful. The HTTP 204 No Content success status response code indicates that a request has succeeded, but that the client doesn't need to navigate away from its current page.

So, which one to use?

Suppose the POST request is for creating some resources. And say the request is successful.


In case you want to send back the data itself,

then you could use 200 OK status code with the full data in your response body.

In caase you want to send back the URL of the data,

then you could use 201 Created status code with the location(ex. links to the resource created) in your response header.

In case you want to send back no content,

then you could use 204 No Content status code. This implies that like for save event, the user agent does not need to traverse away from its current "document view".

Related Links