dadads
dadads

Reputation: 201

Proper HTTP response for unsupported page format (e.g. xml)?

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?

Upvotes: 3

Views: 892

Answers (2)

home
home

Reputation: 12538

I'd use 400. See e.g. http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Upvotes: 0

hmakholm left over Monica
hmakholm left over Monica

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

Related Questions