Post Top Ad

Asp.Net Core Mvc

Blazor

Post Top Ad



Remove the XML Formatter from ASP.NET Web API


ASP.NET Web API's default output format is supposed to be JSON, but when I access my Web APIs using the browser address bar I'm always seeing an XML result instead. When working on AJAX application I like to test many of my AJAX APIs with the browser while working on them. While I can't debug all requests this way, GET requests are easy to test in the browser especially if you have JSON viewing options set up in your various browsers. 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 WebApiConfig.cs file: public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Formatters.Remove(config.Formatters.XmlFormatter); } } #Web #API #Restful #Service #RestAPI #core #API2

No comments:

Post a Comment

Post Top Ad