Skip to content
Ameen Abozaid
Planned lessonJNR-017-L03

Content negotiation

  • Lesson 3 of 6
  • Junior
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 with Content-Type.
  • Accept: application/json asks for JSON. Accept: application/xml asks 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, produces and consumes on a mapping declare what an endpoint supports.
Draft outline details

Demonstration

java
@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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.