We have a REST API endpoint which creates a presigned url (/createPresignedUrl
) to upload file.
How that works is when API call is fired, server would create a presigned url and send that in response. Later, client would use this presigned url to submit the file to our server.
Should that endpoint(/createPresignedUrl
) be GET/POST?
I personally find this as an action being performed by the server, and using the POST.
As its not fetching any actual resource from server, I haven't set this as GET.
I am on the crossroads right now. Should I go for GET/POST? It would be great to get some help here. Thanks.
-
1It's POST. Absolutely. It has side effects, It creates a new resource, it should not be idempotent and it should not be cached. Otherwise you would have only one URL to upload files.Laiv– Laiv2021年07月02日 17:27:56 +00:00Commented Jul 2, 2021 at 17:27
1 Answer 1
From developer.mozilla.org:
GET
The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.
POST
The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.
My Point of View:
From the client perspective it looks like retrieving data.
But from the server perspective its creating a new ressource and in the response parts of that ressource are returned.
Therefore i would use POST. It makes clear that this action will create something in the backend.
-
2To add to this answer: the GET method is idempotent. You must be able to repeat the request without unintended side-effects and intermediate (proxy) servers can answer it with a cached value instead of sending the request to the actual application server.Bart van Ingen Schenau– Bart van Ingen Schenau2021年07月02日 06:04:32 +00:00Commented Jul 2, 2021 at 6:04
-
Yes, I never saw GET in that perspective that it should be cache-able. Thanks. We are moving forward with POST for this. Thank you JanRecker and @BartvanIngenSchenausam– sam2021年07月06日 14:04:47 +00:00Commented Jul 6, 2021 at 14:04