I'm building a REST API endpoint that creates an Excel file export and I'm wondering if this should be a GET or POST request. I can think of several reasons to do either.
In general I'd use GET for fetching data and POST for creation, but this seems to be a bit of a grey area.
This endpoint will be called from JS on button click so there is no limitation there for either one or the other.
Reasons to use GET:
- The file is not stored anywhere, so no state is updated on the server.
- The endpoint could be bookmarked (although it's not a requirement).
Reasons to use POST:
- Technically something gets created, so the action is not idempotent even though nothing is saved.
- In the future complex filters might be added which could get complex if these have to be added in the query string.
- The response might change on consecutive requests so it cannot be cached.
What's the recommended HTTP request method in this scenario?