By default, Web API produces XML but if there is need for JSON, given syntax will do it.
Open WebApiConfig.cs file in solution and add mentioned line in it as shown in example.
- public static void Register(HttpConfiguration config)
- {
- config.Routes.MapHttpRoute(name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new
- {
- id = RouteParameter.Optional
- });
-
- config.Formatters.JsonFormatter.SupportedMediaTypes.Add(newMediaTypeHeaderValue("text/html"));
- }
Kindly provide your valuable comments if you find the post helpful.