I'm developing a forum API in JAVA using Spring and I been refactoring my URLS so they are nested using a maximum of 2 levels.
For example I have the following endpoints in UserPostController:
(GET) /api/v1/users/{username}/posts
(GET) /api/v1/users/{username}/posts/{postId}
(POST) /api/v1/users/{username}/posts
(PUT) /api/v1/users/{username}/posts/{postId}
(DELETE) /api/v1/users/{username}/posts/{postId}
(The posts cannot exists if they aren't linked to an existing user)
But I also wanted an endpoint that let me get ALL existing Posts of ALL Users so I figure I't will be something like:
(GET) /api/v1/posts
I created another controller called "PostController" for that but only with that endpoint.
The problem is that I have another relationships like this one, for example between Post and Comments, and I will end up creating a lot of Controllers for the cases when I want to GET ALL CHILDRENS OF ALL PARENTS. I'm sure there is another better way.
Edit: I also have to mention that the base path for the UserPostController is "/api/v1/users/{username}/posts".