← Back to Chapters

415 Unsupported Media Type

? 415 Unsupported Media Type

? Quick Overview

The 415 Unsupported Media Type HTTP status code indicates that the server refuses to accept the request because the payload format is not supported. This usually happens when the Content-Type header does not match what the server expects.

? Key Concepts

  • Occurs during client-to-server data submission
  • Related to incorrect or missing Content-Type
  • Common in APIs and RESTful services
  • Server understands the request but rejects the format

? Syntax / Theory

HTTP requests that include a body (POST, PUT, PATCH) must specify a valid media type using the Content-Type header. If the server does not support that type, it responds with 415.

? Code Example(s)

? View Code Example
// Sending JSON data without proper Content-Type
fetch("/api/user", {
method: "POST",
body: JSON.stringify({ name: "Meghraj" })
});

? Live Output / Explanation

Server Response

The server responds with 415 Unsupported Media Type because the request does not specify Content-Type: application/json.

? Interactive Example

Select a header below to see how the server responds:

Waiting for request...
? View Source Code for this Logic
// Correct request with supported media type
fetch("/api/user", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ name: "Meghraj" })
});

?️ Use Cases

  • REST API validation
  • Backend request filtering
  • Security enforcement for payload formats
  • Preventing unsupported file uploads

✅ Tips & Best Practices

  • Always set the correct Content-Type header
  • Validate payload formats on the client
  • Document supported media types in APIs
  • Use proper error handling on the server

? Try It Yourself

  • Send a request with an invalid Content-Type
  • Fix the header and observe the response change
  • Test with JSON, XML, and form-data