У меня есть проект веб-API, который возвращает некоторые данные о продуктах. Он корректно согласовывает тип возврата в зависимости от заголовка Accept (JSON/XML) запроса. Проблема в том, что если заголовок Accept не указан, он возвращает XML, но я хочу, чтобы он возвращал JSON по умолчанию.
http://website.com/MyPage?type=json // returns json
http://website.com/MyPage?type=xml // returns xml
http://website.com/MyPage // returns xml by default
Вот мой текущий код выглядит следующим образом:
GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add(
new QueryStringMapping("type", "xml", new MediaTypeHeaderValue("application/xml")));
GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(
new QueryStringMapping("type", "json", new MediaTypeHeaderValue("application/json")));