1

As far as I know, according to RESTful guidelines, every url should represent a single resource or a group of resources, and actions should be put as arguments.

Assume we have a group of resources named 'users', and I want to register one more user,
so the api could be:

POST /users HTTP/1.1
Host: www.example.com

username=<username>&password=<password>&email=<email>&age=<age>

Now if I want to unregister a user, then of the unregister api:

Method will still be POST,
URI will still be /users,
arguments may be username=<username>&password=<password>&reason=<reason>

In this situation, two apis share the same url and method with different arguments, and I think it's not a good design.

So question is:
What is the good design against this situation, to make the server-end easier to distinguish two different actions on the same resource?

EDIT
I really appreciate @Tim's suggestions and now I want my question to be more generic:
If there are several different updating actions on a resource, and each of the actions takes different combination of arguments, how should I work out RESTful apis now? Thanks a lot. :)

dastan
  • 1,006
  • 1
  • 16
  • 36

1 Answers1

2

If you register a user by making a POST (create) request, the opposite - unregistering - should be a DELETE request.

Registering

POST /users HTTP/1.1
Host: www.example.com

username=<username>&password=<password>&email=<email>&age=<age>

Unregistering
You can choose to make a request to /users with the username and password (for verification) in the request body

DELETE /users HTTP/1.1
Host: www.example.com

username=<username>&password=<password>&reason=<reason>

Or make a request to /users/<username> with the password (for verification) and a reason (for whatever purpose) in the request body

DELETE /users/<username> HTTP/1.1
Host: www.example.com

&password=<password>&reason=<reason>

I think the latter is better.

Tim
  • 41,901
  • 18
  • 127
  • 145
  • How to work it out depends on what you use for backend, but i think that is an entirely different issue that deserves its own question :-) – Tim Oct 18 '14 at 13:56
  • 'what you use for backend', can you explain more? Sorry I'm not quite clear about what you mean. – dastan Oct 18 '14 at 15:01
  • When you said `how should I work out RESTful apis now?` i thought you were asking help setting up your server/backend – Tim Oct 18 '14 at 15:22
  • I've proposed a new [question](http://stackoverflow.com/questions/26447254/restful-apis-when-multiple-actions-on-the-same-uri), please check it out. :) – dastan Oct 19 '14 at 04:23