Reputation: 12948
I have a very straight forward problem, yet it is hard to find a formal standard. I have a REST endpoint like this.
/hotels?country=someCountry&city=someCity
If someone going to call it like this
hotels?country=usa&city=tokyo
there will be a conflict in params that the client has provided. What is the appropriate status code for the response (Error Response)? I know it would be OK to send 400 - Bad Request. But I need a more concrete answer.
Edit
I understand this can be easily solved in /{country}/{city}/hotels
manner. Here I need to address this question in more generic perspective.
Another Example
/transactions?startDate=someDate&endDate=someLaterDate
I try
/transactions?startDate=2012-09-03&endDate=2001-08-04
Upvotes: 1
Views: 88
Reputation: 13983
I would not even send an error response, but return status code 200
and an empty list. There is nothing wrong with this request, there is just no match in the database for the given query, then just return []
.
This must then be handled appropiately in the client.
If that endpoint did not even exist (e.g. no route for /hotels
), then 404
would be the correct response.
Upvotes: 1
Reputation: 99533
I think I would put a bit of a different spin on it. Instead of this being a conflict, you can also look at it as "The city Tokyo does not exist in the US".
I think this is a better way to think about it. There's also a few cities that exist in countries you might not expect. (There's a Paris in Canada, and one in the US).
So if you just consider this a 'non-existent city' in a valid country, maybe it's just a 404.
Aside tip: You should use standard ISO 2-letter country codes. They're the most common way to abbreviate countries.
Upvotes: 1