@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
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?
Please or to participate in this conversation.