restformaturl-design

Pass rest resource output format in url


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:

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?


Solution

  • 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.