Does Delicious use GET requests for creation instead of POST, and why shouldn't I do the same?

StackOverflow https://stackoverflow.com/questions/8802838

  •  15-04-2021
  •  | 
  •  

I'm looking at the Delicious API and see the following is the operation to create a new bookmark:

https://api.del.icio.us/v1/posts/add?&url={URL}&description={description}

It looks like they're using a GET request to create server-side database entries, which I've read elsewhere shouldn't be done with GET requests, only with POST requests.

I'm writing my own API right now and I think that it's fabulous to let users interact with the API directly from the URL. But you can't do this unless you allow CRUD operations over GET.

So, is Delicious really doing CRUD operations over GET? Is there an important reason I shouldn't do the same thing in my API, or is POST just mandated for CRUD to prevent accidental invocation?

有帮助吗?

解决方案

Accidental invocation is part of it; that's what the HTTP spec means when it talks about "idempotent" methods. But you could argue that what Delicious is doing is actually idempotent as long as the URL only gets added once no matter how many times you GET. But more importantly is that GET is safe:

The important distinction here is that the user
did not request the side-effects, so therefore
cannot be held accountable for them.

From an interface design standpoint, you want user-agents to make POST and PUT and DELETE more difficult than GET, or at least distinctly different, so that users can rely on that difference to hint when their actions might cause a change in the resource state, because they are responsible for those changes. Using GET to make changes, even if idempotent, blurs that line of accountability, especially when prefetchers are widely deployed.

其他提示

That depends if you follow the REST principles GET for changing things is forbidden. Therefore most people say with REST use POST for changes.

However there is a difference between GET and POST. According to the RFC GET requests have always a followup RESPONSE. And if you use POST you need to follow the Redirect-After-Post pattern.

Another limitation is that URLs may have a limited size. So GET will only work as long as your input data is short enough. So the delicious API has there a bug. You will not be able to add every possible url via a GET parameter.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top