Home > database >  HTTP GET restful to do something
HTTP GET restful to do something

Time:11-25

I'm a little bit confused by what verb I should use / good practice for when I want to do something. For some context, I am building an API where I can get a collection of films. Naturally this fits in nicely within a restful context using a GET http://foo/api/v1/films/name. However, what if I wanted to translate that film given the type of film how would you approach this restfully? I have http://foo/api/v1/translated/films or api/v1/films/name/translate. This however isn't restful. A post doesn't make sense as I'm not creating anything. GET seems the right fit but also doesn't..

CodePudding user response:

You could work with a put verb because of your context needs update/translate something that already exist and the type of film you can send as a parameter.

CodePudding user response:

Today (2021-11-24), there is an unavoidable tension.

So if you are trying to send (arbitrary) information to the server to get some information back, GET doesn't work (generally).

Therefore, you fall back to using POST.

POST serves many useful purposes in HTTP, including the general purpose of “this action isn’t worth standardizing.” -- Fielding, 2009.


In the future, we should have another alternative to choose from.

Late in 2020, the HTTP working group voted to adopt a GET-with-a-body proposal; the document is still in Draft status:

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

So, someday maybe? we will have a safe method with a body, that can be used for messages like "please do something interesting with the body of this request, and send me a representation of the result".

  • Related