Network Deployment (Distributed operating systems), v8.0 > End-to-end paths > Web services - RESTful services


 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 used to exchange data. JAX-WS

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 the 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 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. We 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.



Related tasks

Implement content negotiation based on URL patterns
Implement content negotiation based on HTTP headers
Implement content negotiation based on request parameters

Related reference

Web services specifications and APIs









+

Search Tips   |   Advanced Search