O'Reilly logo

RESTful Web Services Cookbook by Subbu Allamaraju

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Content Negotiation

Content negotiation, or conneg as it is sometimes called, is the process of selecting the best representation of a resource for a client when there are multiple representations (or variants) available. Although content negotiation is often associated with the practice of indicating media type preferences, content negotiation is also used to indicate preferences for localizing by language, character encoding, and compression.

HTTP specifies two types of content negotiation. These are server-driven negotiation and agent-driven negotiation. Server-driven negotiation uses request headers to select a variant, and agent-driven negotiation uses a distinct URI for each variant.

This chapter discusses the following recipes that deal with content negotiation:

Recipe 7.1

Use this recipe to decide which Accept-* headers to include when requesting a resource and with what values.

Recipe 7.2

Use this recipe to learn how to implement servers that correctly interpret the Accept request header for media type negotiation.

Recipe 7.3

Use this recipe to learn how to implement language negotiation using the Accept-Language header.

Recipe 7.4

Use this recipe to learn how to determine the requested character encoding for a representation.

Recipe 7.5

HTTP allows clients to indicate their preference for compressed representations via the Accept-Encoding request header. Use this recipe to decide how to process this header on the server.

Recipe 7.6

Use this recipe to learn how to use the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required