开发者

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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜