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

Kazuto's avatar
Level 2

API - Naming convention for single-action controller

Hey guys,

I'm wondering of there is a naming convention or best practice for naming single-action controller in an API context. I couldn't find anything to it online, neither for Laravel nor other frameworks/languages.

Do you have a preferred naming and what is your opinion about it?

0 likes
5 replies
JeffreyWay's avatar

I'd keep it very simple and CRUD-like. If it's a single action to mark a best reply in a forum thread like this one, then I might call it MarkBestReplyController.

Snapey's avatar

What @jeffreyway said, and also create an Http/Controllers/Api folder and put them in there.

martinbean's avatar

@kazuto I seldom have single-action controllers in an API, as I find with a little bit of thinking there’s almost always a better name for what it is I’m trying to do.

Are you able to tell us what your single-action controller route be doing? As then someone may be able to suggest an appropriate “resourceful” name for the action.

Kazuto's avatar
Level 2

@martinbean More or less CRUD operations. In our company we're using single-action controllers for our API as we have somewhat of a complex business logic. That's why we switched from CRUD-controllers to single-action.

I also prefer @jeffreyway 's naming scheme. Basically Action+(Intention)+Model and thus like to name the controllers like "ListPostsController" though some in our company argue for "ViewPostListController" even though no "view" is returned and MVC doesn't really apply to an API.

So to end the discussion I was looking around the web if there was someone who already "argued" how to name controllers, but I've only found resources about controller naming in MVC context.

martinbean's avatar

@kazuto I think you’re just proving my point a little there, though. With a little more thinking, then “listing” posts is just an “index” action for a “post” resource:

Route::get('posts', [PostController::class, 'index']);

When thinking about “actions” and “intentions”, it pays to just think a little further than that. Think about the side effects of the action. As in, when the action’s preformed, then what is created or amended by that action? This will then lead you towards what resource is actually being manipulated, and the best HTTP method used to operate on it.

For example, riffing on Jeffrey’s example, marking a reply as “best” would be updating a “best reply” resource for a parent thread resource, so you could have a nested resource controller for handling that:

Route::put('threads/{thread}/best-reply', [ThreadBestReplyController::class, 'update']);

You could then pass the reply ID in the body, and have validation to check that the submitted reply ID actually belongs to the thread you’re trying to set it as best reply of.

Please or to participate in this conversation.