Ich habe folgenden CodeWebAPI mvc 4 Satz Standardantworttyp
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
config.Formatters.JsonFormatter.MediaTypeMappings.Add(
new UriPathExtensionMapping("json", "application/json"));
config.Formatters.XmlFormatter.MediaTypeMappings.Add(
new UriPathExtensionMapping("xml", "application/xml"));
Jetzt möchte ich, wenn jemand nicht Erweiterung nicht bieten in api wie http://apuUrl/getBooks
es standardmäßig JSON Wert zurückgeben sollte.
Meine folgenden Szenarien arbeiten gut:
http://apuUrl/getBooks.json
-> liefert JSON
http://apuUrl/getBooks.xml
-> liefert XML
Hinweis: Ich möchte nicht zusätzliche Routing für jede API
Mögliche Duplikate: http://stackoverflow.com/questions/13053485/return-either-xml-or-json-from-mvc-web-api-based-on-request – smoksnes
Ich sah dies ... Aber das erfordert ein zusätzliches Routing für jedes API –
Es kann auch durch Festlegen von Inhaltstyp erreicht werden. Ist das eine Option, oder muss es in der Route sein? – smoksnes