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

MasseElch's avatar

Rest Api - Url Naming Conventions and Code Organization

Hey guys,

im starting my first ever API poject with Lumen and i have some questions regarding REST and Code Organization.

I have 3 entities:

  • user

  • shoppinglist

  • listitems.

  • user hasMany shoppinglists

  • shoppinglist hasMany items

How do i organize the urls or this setup? Especially for the relations between them?

Do i go something like:

... /api/users/{user_id}/shoppinglists/{list_id}/items/ ...

or do i create enpoints like this?

... /api/users/
... /api/shoppinglists/
... /api/items/

Regarding code organization: Since all my Shoppinglists belong to a user, will the crud-methods for the shoppinglists go into UserController? Do i need an extra ShoppinglistController?

Regards, MasseElch

0 likes
3 replies
phpMick's avatar
phpMick
Best Answer
Level 15

I would have a controller for each entity.

CRUD stuff for shopping list would go in ShoppingListController.

I can't see anywhere that you can get resource controllers in Lumen, I would take a look at these in Laravel and define similar routes for your REST stuff.

Hope that helps.

I would also watch this:

https://streamacon.com/video/laracon-us/amanda-folson-apis-with-lumen

MasseElch's avatar

Thanks man, the video helped a lot. Have my upvote, Sir!

1 like

Please or to participate in this conversation.