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 : 

http://localhost:18308/api/values?format=json

for xml 

http://localhost:18308/api/values

OR 

http://localhost:18308/api/values?format=xml