-1

With Web Api, how can I allow the user to choose whether they get JSON or XML back from the web service?

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304

1 Answers1

1

Web API out of the box allows the client to choose what format they want back from the server. They can send:

Accept: application/json

in the HTTP header to get JSON back, and:

Accept: application/xml

to get XML back. JSON is the default if no Accept header is specified.

This is referred to as content negotiation and you can learn more about it here:

http://www.asp.net/web-api/overview/formats-and-model-binding/content-negotiation

Youssef Moussaoui
  • 12,187
  • 2
  • 41
  • 37