2021年1月7日星期四

Is an HTTP method that doesnt change the server state but returns a new resource every time idempotent?

I am implementing REST routes in my server which return a new URL every time, but don't change any server "state".

In particular, I'm writing a route similar to this:

GET/POST example.com/upload-url

What this route does is creates a unique URL that the caller can then use to securely upload a file to the server. Specifically, it will create an S3 presigned put request, and return it. The route handler does not create the file in S3. You can also call this REST route 3 times in a row and have no effect on the server. It also will not invalidate other URLs returned by the server.

For example, suppose you call this route 3 times in a row:

GET example.com/upload-url

The three returns will be different, and might be:

example.com/aaa  example.com/bbb  example.com/ccc  

Each of the returned URL have their own expiration time. Until each one expires, it is completely valid. You could then use each URL, and your file would be uploaded. One caveat, if you uploaded a file using example.com/aaa and then uploaded a different file using example.com/bbb, the file you uploaded using aaa would be overwritten.

The question is - defined this way, is GET example.com/upload-url idempotent?

https://stackoverflow.com/questions/65622471/is-an-http-method-that-doesnt-change-the-server-state-but-returns-a-new-resource January 08, 2021 at 10:05AM

没有评论:

发表评论