RESTful URL for "Activate"

I know I am a bit late but maybe this might be useful for others.

You can create a noun from your operation and use it as sub-resource: activate -> activation

Now you can use POST and DELETE on this sub-resource.

For example:

POST /projects/:id/activation       <-- activate project
DELETE /projects/:id/activation     <-- deleting the activation = deactivate

This pattern can work quite well for operations that toggle between on/off state of something.


Your can send your requests just to projects/{id} and use PATCH (as you're updating existing object) verb, e.g.

PATCH /projects/123

[
    { "op": "activate|deactivate", ... }
]

Read more: REST API - PUT vs PATCH with real life examples


The most conventional way to do this is via POST to /projects/:id, with parameters indicating whether you want to activate or deactivate or something else (always leave room for something else).

note that RESTful URLs should refer to things (like projects), not actions. Then the common methods have clear meanings:

  • PUT: create or replace the thing
  • PATCH: set properties of the thing
  • POST: perform an operation on the thing
  • GET: retrieve the thing
  • DELETE: delete the thing

Tags:

Http

Url

Rest

Api