How to implement non-CRUD features into a RESTful API?

Question

I'm building an app with ReactJS which uses a JSON API provided by Laravel. I'm trying to design the API in a RESTful way but i'm finding some cases hard to deal with.

How do I deal with cases where I need 'special' functionality above normal CRUD stuff? For example, on the 'List' view of my app I have it so that items can be tagged. When a user tags an item from the main list view, the system finds all items with the same name and automatically tags them with the same tag so the user doesn't have to do each one individually.

I've built this functionality directly into the /resource/{id}/update call of the API so updating one item causes others to be updated too, but that isn't actually what I want.

I only want this 'mass update' to work when the user is in this specific list view, all other times the update should not effect any records except the one being updated. How can I implement this without adding 'special case' code to my update endpoint?


Show source
| rest   | php   | api   2017-08-08 21:08 1 Answers

Answers to How to implement non-CRUD features into a RESTful API? ( 1 )

  1. 2017-08-08 21:08

    You could create a new virtual resource-endpoint which does not correspond directly to the objects from the ORM, but a class that handles the issue for you. Pardon the poor naming attempt, but perhaps something like /itemstagger/{itemid}/update'.

    That class can then handle the special cases for you.

Leave a reply to - How to implement non-CRUD features into a RESTful API?

◀ Go back