Map Using content negotiation to serve multiple content types in JAX-RS applications

One of the advantages of RESTful applications is the ability to return different representations of resources. With Representational State Transfer (REST), clients and servers can exchange resources of the same media type or use differing media types. Content negotiation enables clients and servers to agree on the content format that is used to exchange data.

About this task

Resources are represented by many different formats. XML, JavaScript Object Notation (JSON), Atom, plain text, PNG, JPEG, GIF, and custom or proprietary formats are used to represent resources. Representational State Transfer (REST) provides the flexibility to represent a single resource in multiple formats.

Depending on the requirements of your application, resources can return representations in a single format or in different formats, depending on the request. For example, resources accessed using JavaScript clients might prefer JSON representations because JSON is easy to consume. However, other clients prefer XML.

Use content negotiation if you want to serve multiple formats to clients. Content negotiation is the method in which the client and server agree on the response content type to use. There are three types of content negotiation that affect the response. You can use content negotiation that is based on the URL, based on a request parameter, or based on HTTP headers.

Procedure

  1. Configure the development environment.
  2. Define the resources in JAX-RS web applications.
  3. Configure the JAX-RS application.
  4. Implement content negotiation to serve multiple content types.
  5. Assemble JAX-RS web applications.
  6. Deploy JAX-RS web applications.

Results

You have implemented content negotiation to determine the formats for resources to represent data.




In this information ...


(Index)

IBM Redbooks, demos, education, and more


Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.



Terms and conditions for information centers | Feedback

Last updated: Feb 6, 2014 8:04:11 PM CST
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=matt&product=was-nd-mp&topic=twbs_jaxrs_contentnegotiation
File name: twbs_jaxrs_contentnegotiation.html