0

I have Web API which is set to return data in JSON format. I am including attribute [ResponseType(typeof(Class_Name))] for each Action method so that api documentation (swagger) will show sample response format for each api.

Due to some reason, I want to return XML response for one of the api. Since I have set JSON as the default response type, the attribute [ResponseType(typeof(Class_Name))] for that particular api is showing response in JSON format.

Is there any way, I can show XML response for that single api? Is it possible to achieve the same by settings any attributes or some quick hacks?

halfer
  • 19,824
  • 17
  • 99
  • 186
abhilashca
  • 83
  • 2
  • 9
  • The link will help you https://stackoverflow.com/questions/9847564/how-do-i-get-asp-net-web-api-to-return-json-instead-of-xml-using-chrome – Md. Abdul Alim Nov 10 '18 at 15:00
  • Also another helpful link https://andrewlock.net/formatting-response-data-as-xml-or-json-based-on-the-url-in-asp-net-core/ – Md. Abdul Alim Nov 10 '18 at 15:04
  • Isn't so that if request will have header `Accept: text/html` response will be automatically serialized in xml? Unless, of course, you explicitly removed xml serialization. – Fabio Nov 10 '18 at 21:38

0 Answers0