I am attempting to write a Restful API to control a CMS. There are Objects
(e.g., An instance of an Article
) and each object has multiple Draft
s. To work on an object's Draft
s, I built a URL like this:
/cms/objects/{objectId}/drafts/{draftId}
draftId
s are not unique unless you provide an objectId
.
Hopefully I haven't already messed up with this. But now I have multiple verbs I want to perform on each Draft
. Here's a list of verbs:
CLONE, UNPUBLISH, PUBLISH, UNLOCK, LOCK
The way I approached this is to create an endpoint that has an operation
query param. And here's an example of how you use it:
POST /cms/objects/3232/drafts/1?operation=CLONE
POST /cms/objects/3232/drafts/1?operation=LOCK
Is there a better way to do this? I'm actually upgrading an already existing API, and the way you used to do something like this is like so:
POST cms/objects/3232/duplicate-draft?source-draft-id=1
POST cms/objects/3232/lock?draft-id=1
I prefer my way, because in my eyes it's more consistent (though I am biased). Is there a better way to do this?
By the way, I am aware of this question that is very similar. The reason I'm creating this new one is that mine is laser focused on the "multiple verb" aspect and his isn't. His is more like, "how do I do multiple verbs and can you teach me lots of other stuff about Restful APIs, too?"
Also, I feel that the accepted answer on that question does not sufficiently address this (see his point 2). For example, my Draft
s, do not have a lock=true
in their body so I can't easily map the advice from his Change Password section. My Draft
s have two fields to represent if the Draft
is locked: The user name of the locker and the user id of the locker. It would be inconvenient to have the client pass these both in so my intent above is to abstract that work away from the client.