Answer the question
In order to leave comments, you need to log in
What should be the correct response for PUT and POST requests in a RESTful API?
Good afternoon
There is a simple REST web service.
When creating an entity, I send a response CREATED and location with a link to the entity (guided by this article)
When I got to the PUT method, the question arose, what should be the correct answer
Different resources write differently (who is 204, who is 201), for example , here
How is everything right? What authoritative source should one rely on in such matters?
Answer the question
In order to leave comments, you need to log in
Standard responses
2xx everything is fine
3xx action done
4xx user reaction required
5xx server error
And what codes you send is up to you, the main thing is that you document it.
And do not consider articles as dogma, error statuses only indicate that you have decided to shift part of the data into metadata. This is purely an architectural decision. You can generally send always 200 and add a field to the json
{
"status": "Not found",
"statusCode": 404
}
any 2xx is successful, so 204 is only returned when no response body is sent. 201 When the POST/PUT request was successfully completed and the response contains content (no matter what)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question