HTTP content negotiation and API responses 1 question in 2 chapters

  1. 01Representations, headers and message conversion
  2. 02Sources

Representations, headers and message conversion

  • 1.1 How does HTTP content negotiation select JSON or XML in Spring MVC? Medium 5 min

    An HTTP API returns a response with a status, headers and sometimes a body, not necessarily JSON. The client uses Accept to describe the representations it can receive. Content-Type describes the body actually sent. Spring MVC combines the client's preferences, the endpoint's declared output types and available message converters. To return XML, I serialize the response model with an XML converter rather than just changing the content-type header on JSON bytes.

    Read the full answer

Sources