Content Negotiation in REST

Hello Team

I have a REST API which produces xml content, now another consumer wants the same REST API with JSON API.

is there any built in way to produce the JSON content?

or, should i just branch on the httpHeader/Accept and frame the output content.


You’re on the right track.

Use the JSON built-in services to create the content.

Branch on the Accept header to determine the type of content to create and the Content-Type header to return.

The somewhat tricky part is if the callers will provide different types in the request. IS will “help” you by parsing the content, depending upon your handlers and config settings, putting different variables in the pipeline for your top-level service to use. In this case, you’ll need to first determine what type of input you are passed and take appropriate action.