-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,453
  • 5
  • 45
  • 64
Sachin Kainth
  • 43,353
  • 79
  • 196
  • 295

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
  • 11,874
  • 2
  • 39
  • 35