Example HTTP Response
HTTP/1.1 415 Unsupported Media Type
Accept: application/json- Sending XML when JSON expected
- Wrong Content-Type header
- Unsupported file format
What does this mean?
Can't read that! Like handing someone a Betamax tape in 2024. The server doesn't speak that format.
Technical Definition
The media format of the requested data is not supported by the server.
RFC Says
"The 415 (Unsupported Media Type) status code indicates that the origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource. The format problem might be due to the request's indicated Content-Type or Content-Encoding, or as a result of inspecting the data directly."
Plain English:
415 means 'I don't understand the format of the data you sent me.' For example, sending XML when the API only accepts JSON, or sending an image format the server doesn't support. Check your Content-Type header.
Common Misinterpretation
Don't confuse 415 with 400. Use 415 specifically when the content format/encoding is wrong. Use 400 when the content is in the right format but has validation errors. A malformed JSON payload could be either - use 400 if you can't even parse it.
Ready-to-use code for returning this HTTP status in your application:
// Express.js
app.get('/example', (req, res) => {
res.status(415).json({
error: 'Unsupported Media Type',
message: 'Your error message here'
});
});
// Native HTTP
const http = require('http');
http.createServer((req, res) => {
res.writeHead(415, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: 'Unsupported Media Type',
message: 'Your error message here'
}));
}).listen(3000);