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 anAccept
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 aPOST
orPUT
and may be described by theContent-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.”.