Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kovbo's avatar
Level 1

REST API update architecture using specific actions

Hello guys, I want to ask for your advice with building rest API with Laravel. Especially, Update requests.

I use standard approach to update records just passing new parameters via axios request.

But sometimes I need more specific logic. For example, dealing with User model I would like to send a specific request to block or activate or a user. Of course, I could make specific routes for this purpose:

/users/{id}/block
/users/{id}/activate

and create 2 dedicated controllers. But it seems that this approach does not follow rest principles.

What is the right approach to implement this? I'm thinking to create 2 dedicated service classes (BlockUserService and ActivateUserService) and inject them into User Controller. After that I could send a regular put request with an action name to the Update function of the User controller, and implement something like:

if($request->block)
{
return $this->block($user);
}

Not sure if it s right. And how to pass the action name to the controller in this case? Should I append hidden input with the action name, or use route parameters like: PUT "/users/{id}?action=block"?

Maybe there are other best practices?

0 likes
4 replies
Punksolid's avatar

@kovbo I had/have the same doubt as you, as I researched there are things that aren't perfect in REST, one of the better explanations that helped me was this Adam Wathan spech. It isnt exactly about resful but I think it could help you too

https://www.youtube.com/watch?v=MF0jFKvS4SI

1 like
mushood's avatar

Side Note You dont need to have two dedicated service for this. Its dealing with the same thing which would be UserStatusService.

For the Url /userstatus/{id}/update

In your logic, check the current status, then toggle.

This is applicable if you have only two status and you have a flag in your users table that you need to update.

kovbo's avatar
Level 1

@MUSHOOD - Yeah, sure, in this case it could be just one service. However, I'm wondering how to deal with such situations in general. There can be dozens of different actions in a complex application.

Should I register a route for each action (it may mess up the code), or follow rest architecture somehow passing action name..

mushood's avatar

Pass it the action name which goes to the same function.

Then in your controller function, add a switch and based on the action name, call the function on your service.

Please or to participate in this conversation.