ASP Net Web Api : define data format in url

Content negotiation is one of the strong pointy in web api and thats pretty cool. 

Now i can just change the type of response via url only. 

To achieve this just add the following  one line of code 

GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping(“format”, “json”, “application/json”));


Now i can get json via url : 


for xml 









Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s