Closed martintoreilly closed 7 years ago
See PR #12 for implementation of POST (CREATE), GET (READ), GET (LIST), PUT (Replacement UPDATE), DELETE (DELETE).
See PR #16 for PATCH (Partial update) using JSON merge patch approach.
Closing following merge of PR #16
Description
HTTP endpoint(s) exposing a RESTful API that supports CRUD (Create, Read, Update, Delete) operations on the applications Job repository
Implementation notes
middleware.job.model.py
. Once we switch to a database-backed repo, we will very likely want to have stricter validation as we will likely have a stronger binding between code Job model and database Job model.Job-specific operations
Endpoint:
/job/<string:job_id>
, handlerJobApi
/job/<job_id>
: Retrieve job specification JSON for provided job ID404 - Not found
if no job exists with specified ID200 - OK
with job JSON in message body if job exists with specified ID/job/<job_id>
: Update existing job by replacing with provided complete job JSON (Content-Type: application/json
)404 - Not found
if no job ID provided in URL404 - Not found
if no job exists with job ID provided in URL400 - Bad request
if request body is empty409 - Conflict
if job IDs in URL and request JSON don't match400 - Bad request
if body is not valid JSON400 - Bad request
if body JSON not valid Job JSON200 - OK
with updated job JSON in message body if job exists with specified ID/job/<job_id>
: Delete job specification for provided job ID404 - Not found
if no job exists with specified ID204 - No content
with empty message body if job exists with specified ID/job/<job_id>
: Patch specified job using partial Job JSON provided in body (Content-Type: application/merge-patch+json
)404 - Not found
if no job ID provided in URL404 - Not found
if no job exists with job ID provided in URL400 - Bad request
if request body is empty409 - Conflict
if job IDs in URL and request JSON don't match400 - Bad request
if body is not valid JSON400 - Bad request
if body JSON not valid partial Job JSON200 - OK
with full updated job JSON in message body if job exists with specified IDContent-Type: application/merge-patch+json
). We are not using the JSON patch standard described in RFC 6902, which takes explicit edit operations as input (Content-Type: application/json-patch+json
). While the explicit edit approach of JSON patch would provide maximum flexibility in the low-level Job API, we don't (yet) need this flexibility and using JSON merge patch means we can use similar validation as we do for the PUT action and don't need to work out how to validate patches (to e.g. ensure we don't allow Job ID to change).json-merge-patch
package (source).Generic operations
Endpoint:
/job
, handlerJobsApi
/job
: Creates new job from Job specification JSON (Content-Type: application/json
)400 - Bad request
if request body body is empty409 - Conflict
if job with same ID already exists400 - Bad request
if body is not valid JSON400 - Bad request
if body JSON not valid Job JSON200 - OK
with job JSON in message body if no job exists with specified ID/job
: Lists all existing jobs200 - OK
with JSON array of object representations for existing jobs in message body (i.e.. If no jobs exist then an empty list is returned).{"id": <job-id>, "uri": "/job/<job_id>"}
Note: To expose a unified endpoint URL structure, we've used
/job/
as the root, with the presence or absence of the<job_id>
URL fragment determining which handler to route to.