lante lante - 1 year ago 58
HTTP Question

Status Code for an endpoint that creates but returns no data

I have and endpoint from a REST API that creates an entity, but the endpoint does not return any data.

Would it be ok to return a

status code? or it would be better to return a
status code?

Which one wins?

Answer Source

The 201 status code means that a resource has been created. The 204 status code is not suitable for this situation.

A response for a request that creates a resource should have the 201 status code and the Location HTTP header with a URI that identifies the newly created entity. Quoting the RFC 7231, the current reference for semantics and content of the HTTP/1.1 protocol:

6.3.2. 201 Created

The 201 (Created) status code indicates that the request has been fulfilled and has resulted in one or more new resources being created. The primary resource created by the request is identified by either a Location header field in the response or, if no Location field is received, by the effective request URI. [...]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download