Reputation: 201
I'm trying to create a REST API, where users can request responses in different formats.
For example, user can access:
example.com/oranges/1.xml (returns results in XML)
example.com/oranges/1.json (returns results in JSON)
What's the proper HTTP response to indicate that a specific response format is not available?
For example, user tries to access:
example.com/oranges/1.yml (unsupported format)
Do I throw a 404 or is there a better response?
Upvotes: 3
Views: 892
Reputation: 12538
I'd use 400. See e.g. http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Upvotes: 0
Reputation: 23332
If you're encoding the desired format in the URL, then 404 is indeed the correct response -- it tells the client that it will never, barring server changes, be able to do anything with that URL.
With proper HTTP content negotiation, using the Accept
request-header (which would be the more RESTamentalist choice), the appropriate response for an unsupported type would be 406.
Upvotes: 4