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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With