Another Salesforce blog!!!

Salesforce, Apex

ASP.NET Web API to return JSON or XML data


Add the below code app_start event in global.asax file.In API Url add the query string.

//json
GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(
new QueryStringMapping(“type”, “json”, new MediaTypeHeaderValue(“application/json”)));
//xml
GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add(
new QueryStringMapping(“type”, “xml”, new MediaTypeHeaderValue(“application/xml”)));

eg:
for xml : http://localhost:49533/api/books?type=xml
for json: http://localhost:49533/api/books?type=json

Leave a Reply

Your email address will not be published.

*