I'm developing an API and I always try to use the most correct http status codes for each scenario.
One of this scenarios is the response for POST requests. Per example, a POST method for an endpoint /orders/
receive some informations, like a customer
:
{
customerDocument: {number: "123.456.789"},
// other informations for create a order
}
So, my questions is: if this number
from customerDocument
not exists, is it Ok to return a 404 status code error with a nice message telling that the customer was not found?
I normally use 404 only for GET in the specific resources (the most obvious usage), like:
/customers/{number}/
In business validations like "The customer is not active", I normally use the http status code 422 for any http method (POST, PUT, GET, etc). I'm in doubt if I can use 404 or 422 for my POST example.