Pass rest resource output format in url

82 Views Asked by At

AFAIK every resource have a url in REST design. for example /user/28 is url of user with id equal to 28 and /users will return all users.

There are some way to represent output format of the resource:

  • passing a query parameter like format
  • specify it using extensions(changing /users url to /users.json to get the users in json format)
  • specifying the requested format(xml, json, xls, ...) by setting Accept http header.

I search the web and it seems the correct way is setting Accept header. But if you want to have a http link (specified by href) to download list of users in xls format, you can't!Also if you want to download the xls by the browser, you will encounter many problems(you should use ajax so the xls should download using ajax and etc.)

If it is the best way, what is the solution for download link and if its not, which solution is better?

1

There are 1 best solutions below

0
On BEST ANSWER

The Accept header is considered 'more correct', but there are plenty examples of all the options you mention. As far as I can tell, none of them is considered "bad". Personally, I'd say that you should honor and prefer the Accept header, but a format query parameter should override it, if present. The downside of the 'extension' method is that each format results in a different resource, which can get ugly.