GET request - desired response format in parameter or Accept header

I am working on an ASP.Net Web API 2 RESTful web service to import and export data from my database. For my export method, the client has several options for exporting data in different formats (for example, pdf, xml, etc.). I am trying to determine the best design for my interface so that the client can tell the service whose format will provide the data.

As far as I can tell, my 2 best options are to use the Accept Header with strings such as multimedia or add a parameter to the method in which the client can provide a format parameter in the query string. If I prefer to use the Accept header, this may be due to the use of custom media type strings.

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

Can someone explain what are some of the advantages or disadvantages of these two designs?

+5
source share
1 answer

Both approaches are acceptable ways to get the same result. REST is not a specification for implementation, so any answer you get here will most likely be the preferred way to execute it, or how they understood REST.

Your question is similar to this one from .SE programmers: The trade-off between content negotiation with the Accept header versus extensions . Please also note that in pdf, xml, etc. There are standard recognized mime types, so I don't see the need for custom media type types.

However, my preferred way to get the report would be in the query string ?format=pdf . Go with what is simpler, more convenient, cleaner, etc.

+3
source

Source: https://habr.com/ru/post/1207149/


All Articles