Designing Bulk Updates API With Sub-Resources

92 views
Skip to first unread message

API Dev

unread,
Apr 12, 2018, 9:09:45 AM4/12/18
to API Craft
           Assuming we have a sub-resource api like

/tables/
/tables/{id}
/tables/{id}/fields

/tables/{id}/fields/{id}

What would be a good restful api design for implementing supporting operations like editing just names of multiple tables AND updating individual attributes of a /tables resource.

  1. Bulk edit - PATCH /tables
    POSTDATA: { [ {id: 101, name: T1}, {id: 102, name: T2}]
  2. Bulk edit - PATCH /tables
    POSTDATA: { [ {id: 101, name: T1}, {id: 102, name: T2}]
    1. POST /tables is already used for creating a table. Won't it be conflicting to also use for bulk edits?
  3. Something else?

My doubts are mainly around consistency -  how to keep single and bulk updates api consistent? How to deal with delete operations on a nested resources when introducing PATCH?


Thoughts?


Thanks.

Jørn Wildt

unread,
Apr 12, 2018, 11:10:58 AM4/12/18
to api-...@googlegroups.com
Remember that POST (PUT) and PATCH are different HTTP verbs - and all can be applied to the same resource. You can POST (PUT) /tables and expect something to be created or PATCH /tables and expect a (partial) update to be executed.

See JSON PATCH and JSON MERGE media types for what kind of payload you should use with your PATCH operations.

/Jørn

--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-craft+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/api-craft.
For more options, visit https://groups.google.com/d/optout.

API Dev

unread,
Apr 23, 2018, 10:26:33 AM4/23/18
to API Craft
I have an update on this and a ask for suggestions/thoughts
As an alternative to PATCH I was looking at having a POST api with different resources i.e. for all the properties that need to be updated we group them into domain based categories and expose an api for each category. For e.g. To update the fields that are part of the table we expose a POST /tables/{id}/fields while to update any information related to auditing we expose a POST /tables/{id}/audits api and so on. With this api, the recommendation would to look at POST as an api for creates when it applies to collections like /tables and as an update api when it acts on objects like /tables/{id}/fields. Here fields is an object of the tables resources
I was mainly analyzing this alternative given that java doesn't have enough support for implementing PATCH api with jax-rs annotations. We tried using the json-patch library too but the code isn't maintainable when compared to the POST api implementation code.

Any downsides of preferring the POST api approach for updating an resource instead of PATCH?

Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to api-craft+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages