Content Negotiation and Media Types
Clients and servers can negotiate representation formats using headers such as Accept and Content-Type.
A client might send Accept: application/json, indicating that it wants JSON. A request containing JSON normally sends Content-Type: application/json.
Media types can also be vendor-specific or versioned, for example application/vnd.example.user+json. Content negotiation is different from URI versioning because the representation format is negotiated through HTTP metadata rather than encoded in the path.
A robust API validates unsupported media types and can respond with 415 Unsupported Media Type when the request body format is not supported.
Key Takeaways
Acceptdescribes preferred response representations.Content-Typedescribes the body being sent or returned.- Media types can be used for sophisticated representation negotiation.