ASP.NET Web API supports the concept of media formatters. Based on the content-type you set in your request headers different output can be generated. Default formatters exist for XML and JSON.
However I had a situation where I only wanted to return JSON output. Removing the XML formatter can easily be done through the Web API configuration inside your startup.cs file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code configures Web API. The Startup class is specified as a type | |
// parameter in the WebApp.Start method. | |
public static void ConfigureApp(IAppBuilder appBuilder) | |
{ | |
// Configure Web API for self-host. | |
HttpConfiguration config = new HttpConfiguration(); | |
//Only return JSON | |
config.Formatters.Remove(config.Formatters.XmlFormatter); | |
appBuilder.UseWebApi(config); | |
} |