3
votes

I have reviewed RFC2616. For a "406" it states:

Unless it was a HEAD request, the response SHOULD include an entity containing a list of available entity characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field. Depending upon the format and the capabilities of the user agent, selection of the most appropriate choice MAY be performed automatically.

But, I'm a little confused about what to return and how. For example, if I have a RESTful'ish resource that can only return JSON, and the accept header specifics that the caller only wants XML, how should I tell him that I can only return JSON?

1
If the Web server detects that the data it wants to return is not acceptable to the client, it can return a header containing the 406 error code. Let the client know that you are responding something other than xml. checkupdown.com/status/E406.html - blurfus
So, it seems like returning a header with error code 406 and response content-type of 'Content-type: application/json' should suffice - blurfus

1 Answers

1
votes

I think it's safe to respond with a list of the available content types using the Content-Type the resource provides - in your case Json.

It's kind of a "best-effort" approach of the service and it's the responsibility of the client to react to the problem or abandon the request.

For example if you travel abroad (i.e. to Germany) and go to the local butcher. You only speak English and the butcher only speaks German and French. You ask in English for Beef.
Because the butcher doesn't understand you, he responds in German and French asking you to change the language of your request ("Sprechen Sie deutsch?", "Parlez vous Francais?").

Now it's your choice to: - learn German or French ("Rindfleisch", "Boef") - try another common language (handsigns, primeval sounds) - leave and search for a butcher that understands English