Content negotiation — HTTP and REST · Foundations

One resource, several representations. Answer the list as JSON or CSV depending on what the client's Accept header prefers, refuse what you cannot produce or read with 406 and 415, and tell caches the answer depends on the header.

What you will learn

Read the theory for Content negotiation

All HTTP and REST lessons

All Foundations courses

loading types…

What you'll learn

  • Tell a resource from its representations, and pick one from the Accept header, weighing q-values
  • Refuse with 406 when nothing acceptable can be produced and 415 when a request body cannot be read
  • Say Vary: Accept on a negotiated answer, so a cache does not hand one client's format to another