Closed sam-hunt closed 8 years ago
Could this be implemented easily for "catch-report-simple"? If we can exclude the "Accept" header from the request, it means we only need to provide a link for users to click and the browser will handle all the download stuff
That's exactly my plan :) I could hack this in ASAP if required. And I'll probably do so if I don't have #177 refactored by the end of the weekend.
It would just be nicer to do it after datasets are encapsulated into their own classes. Then it could be as easy as checking the property method of the current dataset object.
API response formats can be specified by adding a supported file extension to the end of the dataset name. i.e.
GET /catch-report-annual.csv?year=2016
GET /user.json
The URL workaround meets our core requirement of having csv-formatted endpoints which don't require explicit text/csv accept headers in the request. With this being trivial now, supporting a default (when no extension is specified) other than JSON becomes mostly redundant.
Also I've removed the text/csv accept switching as suggested by @FrancisG-Massey.
As a second format was only recently added (CSV), JSON is the default for all GET queries unless an 'Accept: text/csv' header is explicitly defined.
It would be nice if datasets could have a property which defines a default format if one is not specified by the request. Then reports intended to be received as downloadable CSV files could be sent like this instead of the JSON default.
This should be easier to implement after #177.