Question

I am doing attach and detach operations in my below controller like detaching the relationship from a OU to a ModuleDevice.

What http verbs would those operations mean in a REST API?

ModuleDevicesToOUController

Api/ModuleDevicesToOU/1/OU/1 // Attach for ModuleDevice with Id 1 the OU with Id 1
PUT/Delete/Patch ??? Attach…

Api/ModuleDevicesToOU/1/OU/1// Detach for ModuleDevice with Id 1 the OU with Id 1
PUT/Delete/Patch ??? Detach…
Was it helpful?

Solution

How about using the LINK method? https://datatracker.ietf.org/doc/html/draft-snell-link-method-08

If that's a little experimental for you then just use POST.

OTHER TIPS

If I understand your API correctly, the call is doing a change in the resource at the server, this means that you should use a POST:

Per RFC 2616 , the POST method should be used for any context in which a request is non-idempotent: that is, it causes a change in server state each time it is performed, such as submitting a comment to a blog post or voting in an online poll. In practice, GET is often reserved, not simply for idempotent actions, but for nullipotent ones, ones with no side-effects (in contrast to "no side effects on second or future requests" as with idempotent operations)

http://en.wikipedia.org/wiki/POST_%28HTTP%29

http://en.wikipedia.org/wiki/Http

This is, in my opinion, a very important point between the difference between GET and POST. POST is not only there to allow you to send information in the body, but also to modify the state of the server. I always have it in mind when designing REST interfaces.

I hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top