With Web Api, how can I allow the user to choose whether they get JSON or XML back from the web service?
Asked
Active
Viewed 124 times
-1
-
You can change return type on demand. Already answered at http://stackoverflow.com/a/12487921/929902 – Teoman shipahi Mar 29 '13 at 22:14
1 Answers
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