Tyring to apply formatting on json and xml at once in a web service:
config.Routes.MapHttpRoute(
name: "DefaultApiWithExtension2",
routeTemplate: "api/{controller}/{id}.{ext}",
defaults: null,
constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
);
config.Routes.MapHttpRoute(
name: "DefaultApiWithExtension1",
routeTemplate: "api/{controller}.{ext}",
defaults: null,
constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) });
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Formatters.XmlFormatter.AddUriPathExtensionMapping("xml", "application/xml");
config.Formatters.JsonFormatter.AddUriPathExtensionMapping("json", "application/json");
But I'm keep getting 400 error, when I'm trying to get response with extension (and without it). None of the routes works:
api/person.xml
api/person
api/person/1.json
api/person/1
If I'm using only "DefaultApi" route - everithing is ok (with no extensions I'm getting json). What am I'm missing?