406, 415, and API Formatting

While working on getting our API restructured, I had to lookup how we want to respond to a client who has requested a format that we don't support. Is it a 406? A 415? Here are some plain English explanations:

  • 406 Not acceptable — In the context of format, when the server can't (or won't) respond in the format that the client has requested. This requested format could come in via an Accept header or an extension in the path.
  • 415 Unsupported media type — when the client has sent content in a request body that the server doesn't support. This would occur during a POST or PUT and may be described by the Content-Type header.

A user on Stack Overflow puts it as succinctly as possible: "406 when you can't send what they want, and 415 when they send what you don't want.".

Posted on July 4, 2012 from San Francisco

Newest Articles