Resource and Action URI convention for REST

Viewed 3556

I am at a cross roads for developing some REST APIs and I have found no real discussion on the subject much less a firm defense of either.

It's my understand that with REST you have /<resource>/<action> as your URL

So, to disable a user you would have:

PUT /user/disable

Seems reasonable. However, we have the debate going on out more basic methods:

should it be:

POST /user  (creates a user *implicitly*)
POST /user/create (creates a user *explicitly*)

DELETE /user/:id
DELETE /user/:id/delete

The first seems to be what is considered "the standard" and the second is obviously much more clear in it's intent and is consistent with methods like /user/disable

Maybe this debate has raged elsewhere but I have not seen it. If you're 'religious' about this, now's your chance to pontificate

3 Answers

Having action in your URL is not REST.

My approach to solve this is to define an action sub-resource.

And you can do something like:

POST /users/123/actions

and request body as json:

{ "type": "reset_password", "current_password": "mypassword", "new_password": "$myNewPass2#" }

Related