GET request - desired response format in parameter or Accept header
Asked Answered
H

1

6

I am working on an ASP.Net Web API 2 RESTful web service for importing and exporting data from my database. For my export method, the client has several options for exporting data in different formats (e.g. pdf, xml, etc.). I am trying to determine the best design for my interface for the client to inform the service which format to provide the data in.

As far as I can tell, my 2 best options are to use the Accept Header with media type strings or adding a parameter to the method where the client can provide the format parameter in the query string. If I choose to use the Accept Header this may involve using custom media type strings.

It seems to me that using the Accept Header would be more inline with HTTP standards and RESTful practices, but using the format parameter in the query string would be easier to implement on the service side and for the client.

Can anyone explain what some of the advantages or disadvantages of these 2 designs are?

Heteroplasty answered 18/11, 2014 at 18:10 Comment(0)
G
4

Both your approaches are valid ways to get to the same result. REST isn't a spec to implement, so whatever response you get here is likely to be someone's preferred way of doing it or how they've understood REST.

Your question is similar to this one from programmers.SE: Tradeoffs between content negotiation via Accept header versus extensions. Do note also that pdf, xml etc have standard recognized mime types so I don't see the need for custom media type strings.

That being said, my preferred way of GET-ing the report would be to have a ?format=pdf query string. Go with whatever is easier, more maintainable, cleaner, etc.

Grit answered 19/11, 2014 at 21:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.