RESTful: How to perform different actions on the same url?

dastan

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. :)

Tim

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to perform different actions depending on parameter type

From Dev

How we can perform different actions in single HTML form for changing url dynamically in django?

From Dev

How to use the same button for different actions in JavaScript?

From Dev

How can I make a Mockito mock perform different actions in sequence?

From Dev

How can I make a Mockito mock perform different actions in sequence?

From Dev

How to make a button in appmaker perform some actions and open a URL after

From Dev

Trying to get two actions to have different views, but the same URL

From Dev

jQuery: How to trigger different actions with the same click function (with different elements)

From Dev

RESTful APIs when multiple actions on the same URI

From Dev

How to perform actions periodically in Erlang

From Dev

How to hide/reveal different actions on the same FloatingActionButton like in Inbox app

From Dev

How to create 2 actions with same path but different HTTP methods DRF

From Dev

How to hide/reveal different actions on the same FloatingActionButton like in Inbox app

From Dev

Perform different actions with a button based on the data attribute

From Dev

Submit Button to Perform Two different actions

From Dev

SwiftUI different actions on the same Custom Alert actions

From Dev

Consuming different input JSON format by same URL and same method in Spring RESTful service

From Dev

Submit same form to different actions

From Dev

How to say to eclipse-maven-plugin perform from eclipse same actions as mvn from cmd

From Dev

How can I perform different actions based on which browser I'm using?

From Dev

Can two rest resources have same methods and request mapping but different @path(url) in Restful service

From Dev

How to parse a RESTful URL

From Dev

How to perform actions for failed builds in Jenkinsfile

From Dev

How to overwrite and perform actions on webpage with AbotX Javascriptrendering

From Dev

How to perform actions on Drupal taxonomy term creation?

From Dev

How does the Linux desktop perform system actions?

From Dev

How to perform actions in order in Swift 4

From Dev

How to map different HTTP methods on the same url to different controllers?

From Dev

Restful - same request but difference response on different scenarios

Related Related

  1. 1

    How to perform different actions depending on parameter type

  2. 2

    How we can perform different actions in single HTML form for changing url dynamically in django?

  3. 3

    How to use the same button for different actions in JavaScript?

  4. 4

    How can I make a Mockito mock perform different actions in sequence?

  5. 5

    How can I make a Mockito mock perform different actions in sequence?

  6. 6

    How to make a button in appmaker perform some actions and open a URL after

  7. 7

    Trying to get two actions to have different views, but the same URL

  8. 8

    jQuery: How to trigger different actions with the same click function (with different elements)

  9. 9

    RESTful APIs when multiple actions on the same URI

  10. 10

    How to perform actions periodically in Erlang

  11. 11

    How to hide/reveal different actions on the same FloatingActionButton like in Inbox app

  12. 12

    How to create 2 actions with same path but different HTTP methods DRF

  13. 13

    How to hide/reveal different actions on the same FloatingActionButton like in Inbox app

  14. 14

    Perform different actions with a button based on the data attribute

  15. 15

    Submit Button to Perform Two different actions

  16. 16

    SwiftUI different actions on the same Custom Alert actions

  17. 17

    Consuming different input JSON format by same URL and same method in Spring RESTful service

  18. 18

    Submit same form to different actions

  19. 19

    How to say to eclipse-maven-plugin perform from eclipse same actions as mvn from cmd

  20. 20

    How can I perform different actions based on which browser I'm using?

  21. 21

    Can two rest resources have same methods and request mapping but different @path(url) in Restful service

  22. 22

    How to parse a RESTful URL

  23. 23

    How to perform actions for failed builds in Jenkinsfile

  24. 24

    How to overwrite and perform actions on webpage with AbotX Javascriptrendering

  25. 25

    How to perform actions on Drupal taxonomy term creation?

  26. 26

    How does the Linux desktop perform system actions?

  27. 27

    How to perform actions in order in Swift 4

  28. 28

    How to map different HTTP methods on the same url to different controllers?

  29. 29

    Restful - same request but difference response on different scenarios

HotTag

Archive