jd182
jd182

Reputation: 3260

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

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?

Upvotes: 0

Views: 226

Answers (1)

Canis
Canis

Reputation: 4410

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.

Upvotes: 2

Related Questions