Situation
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)
Question
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?
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
Acceptrequest-header (which would be the more RESTamentalist choice), the appropriate response for an unsupported type would be 406.