I developed a web-app sometime ago for licensing our software. This has customers, accounts, users and licences. A licence is assigned to a user and activated with a serial number. Licences are created as the output of processing a purchase-order, i.e. there isn't any direct way of POSTing a new licence.
I'm reading "RESTful Web Services" at the moment and contemplating how I would make it RESTful (HATEOAS also).
Most of the URL's I'm clear about, but there are some interesting actions needed on licences. The basic URL for a licence will be /licence/{licenceID}
.
Now, in REST I can only use standard methods and mustn't embed an action say "assign" into the URL. What I'm thinking is to pick out the parts of the licence I want to affect. This gives: -
GET /licences/
GET /licences/{licenceID}
POST /licences/{licenceID}/assignee/{userID}
DELETE /licences/{licenceID}/assignee
POST /licences/{licenceID}/serialNumber/{serialNumber}
DELETE /licences/{licenceID}/serialNumber
POST /licences/{licenceID}/expires
DELETE /licences/{licenceID}/enabled
My questions are: -
/assignments/{licenceId}/{userId}
)Many thanks!
GET /licences/
Fine, though I would use GET /licences
myself :)
GET /licences/{licenceID}
Looks good
POST /licences/{licenceID}/assignee/{userID}
I'd suggest this was counter-productive, unless licences are assignable to multiple licensees. Instead, I suggest
PATCH /licences/{licenceID}
{ assignee={userID} }
or
PUT /licences/{licenceID}/assignee
{userID}
Which to choose should depend on how often the assignee of a license changes. If frequently, use the latter option, if infrequently, use the former.
DELETE /licences/{licenceID}/assignee
Good. If you use this though, then you should use the second of the two storage options given previously. If you chose the first one, then something like:
PATCH /licences/{licenceID}
{ assignee=NULL }
POST /licences/{licenceID}/serialNumber/{serialNumber}
DELETE /licences/{licenceID}/serialNumber
POST /licences/{licenceID}/expires
You can treat these three the same as you decide for assignee to make things easier for your clients.
DELETE /licences/{licenceID}/enabled
I suggest:
> DELETE /licences/{licenceID}
< 201 Created
< Location: /disabled-licenses/{licenseID}
The URI namespace /licenses would then map to your domain model licenses WHERE valid==true
and /disabled-licenses would map to licenses WHERE valid==false
. There's nothing wrong with that. Access to invalid licenses can then be restricted at the HTTP level (i.e. by URI path) rather than at the application level (by checking the field value in your database).
My questions are: -
/assignments/{licenceId}/{userId}
)Your suggested scheme is mostly good with some alterations.
No, not really.
Again, if a license only has one user ID and one serial number, then the values of those are resource properties and/or subresources. If modeled as subresources, they belong in the URI, if properties, then in the body.