Reputation: 8722
Lets say I have an endpoint in my API with the following URL:
www.example.com/api/create-order-for-restaurant/
Now, in my POST request, I send the following data:
{
"restaurant_id": 43,
"order": {...}
}
Lets say a restaurant with the id 43 does not exist in my database. What should be the appropriate HTTP status code that should be sent back to the client?
Im confused if I should be sending back 404
or 500
.
Upvotes: 0
Views: 178
Reputation: 99533
This is a client error because the client specified a restaurant_id that didn't exist.
The default code for any client error is 400, and it would be fitting here too. There are slightly more specific client error codes that might work well for this case, but it's not terribly important unless there is something a client can do with this information.
So 400, 422 is fine. 500 is not. 500 implies that there's a server-side problem, but as far as I can tell you are describing a situation where the client used an incorrect restaurant_id.
Upvotes: 2