Hi all,
How might you go about modelling a REST request to create
a collection of resources, where the elements in the collection are
determined by complex application logic? In other words, the client knows generally the collection it wants to create, but the server knows the specific elements to put in the collection.
Example.
I have the following resources:
/items - describes a "thing" that a person might own. e.g. "house", "car"
/assets - describes the thing that a person possesses. e.g. "my house", "my car"
/tasks - describes a pre-defined task that a person needs to do to the item they own. e.g. "clean gutters", "change tires"
/todolist - relates tasks and items, in a realized kind of way. e.g. "clean my gutters", "change my tires"
To query the todolist related to an asset, we have:
GET /todolist?asset="my house"
It's easy enough to allow a client to add items to the todo list:
POST /todolist {asset:"my house", task: "clean gutters"}
One
feature of our application is that we can automatically populate your
todolist based on the state of your asset (your house has no gutters?
we don't add that task to your todolist).
For a variety of
reasons we do not populate that list immediately when you create the
asset resource. Instead, there's an engine that wakes up periodically
and looks for todolists that need initializing or updating. For some
users, that isn't happening fast enough. But since the logic on how we
relate these 3 resources to create the todolist is complex (and
inappropriate to expose to clients), we are contemplating exposing the
ability to trigger the engine to initialize their todolist on demand.
The first thought that occurs to me is something like
POST /todolist?asset="my house"
with no payload. Is that weird, given that we already have a different POST syntax on that resource?
How would you do it?
Cheers and thanks,
Julie