I am aware of a well-known question here: PUT vs POST in REST
However I am a bit confused in one of my case and would want to seek for advise to properly design my RESTful WS:
Assume my system work like this:
My system will have multiple batch jobs defined (e.g. JOB1
, JOB2
).
For every day, I will ask my system to create a list of batch job schedule, by providing a specific date (e.g. I passed in 2014-12-25, then system will create JOB1(2014-12-25)
and JOB2(2014-12-25)
.
User can trigger a batch job schedule to execute.
I want to seek for advise to proper expose these as resource:
Should I do a POST or PUT to the resource /batchSchedules
to trigger the creation of batchSchedules
for a specific date? How should the URL looks like to make it a proper RESTful API?
What should the "schedule triggering" looks like?
I am thinking of these two choices, but both doesn't sounds quite right to me:
Approach 1:
To create schedule for a specific date: PUT
to /batchSchedules/2014-12-25
with empty request body, as it seems that I am creating "bunch of schedules" as the resources declared in URL. (However, it does seems right because I am not going to replace it if I call it again, which doesn't looks quite well)
To trigger a schedule execute: PUT
to /batchSchedules/2014-12-25/JOB1
as it seems replacing the batch schedule resources (but it looks strange coz I am not really replacing the resource, cannot take a POST here because I am actually not generating a child resources below the URL)
To get the status of a schedule with meaningful input: GET
/batchSchedules/2014-12-25/JOB1
To get the status of a schedule: GET
/batchSchedules?id=12345
which 12345 is the ID for a schedule
Approach 2:
To create schedule for a specific date: POST
to /batchSchedules
with date in request body, as it seems that I am creating a child resource of batch schedules
To trigger a schedule execute: PUT
to /batchSchedules/2014-12-25/JOB1
as it seems replacing the batch schedule resources (but it looks strange coz I am not really replacing the resource, cannot take a POST here because I am actually not generating a child resources below the URL)
To get the status of a schedule with meaningful input: GET
/batchSchedules/2014-12-25/JOB1
To get the status of a schedule: GET
/batchSchedules?id=12345
which 12345 is the ID for a schedule
Approach 3:
To get the status of a schedule with meaningful input: GET
/batchSchedules?job=JOB1&date=2014-12-25
To get the status of a schedule: GET
/batchSchedules/12345
which 12345 is the ID for a schedule
To create schedule for a specific date: POST
to /batchSchedules
with date in request body, as it seems that I am creating a bunch of child resources of batch schedules under /batchSchedules
(doesn't seems quite good)
To trigger a schedule execute: PUT
or POST
to /batchSchedules?job=JOB1&date=2014-12-25
as it seems replacing the batch schedule resources (looks really strange to me)
Which of them is the appropriate way of exposing my WS in proper REST manner?