Reputation: 1520
What HTTP status code should be sent to user if his post request is correct but there is nothing has been updated in database as user is sending the same value for every field which already been there in database?
Upvotes: 1
Views: 87
Reputation: 93
You will use 204 in this case.
The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.
If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.
The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.
Upvotes: 1
Reputation: 844
A 200 status would definitely be perfectly appropriate in this case.
What you are describing is usually something that an application on top of the HTTP-based API would handle/add as context.
One lesser-known status code which could be used in such cases, however, is 204.
"The 204 (No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to return in the response payload body"
In other words, depending on your application's setup, you could use a 204 (with no response body) to indicate that the PUT/update request itself was successful. but that nothing was modified.
See here for further reading on 204: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-p2-semantics-19#section-7.2.5
Upvotes: 1