Content negotiation
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
let the client and server agree on a format.
Planned topics
- The client says what it can read with
Accept. The server says what it sent withContent-Type. Accept: application/jsonasks for JSON.Accept: application/xmlasks for XML.- If the server cannot produce the requested type, it answers
406 Not Acceptable. - If the client sends a body type the server cannot read, the answer is
415 Unsupported Media Type. - In Spring,
producesandconsumeson a mapping declare what an endpoint supports.
Draft outline details
Demonstration
@GetMapping(value = "/products/{id}", produces = "application/json")
Product get(@PathVariable long id) { ... }Check your understanding
Which status does a client get when it posts XML to a JSON-only endpoint?
Show answer
415.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.