0

I am developing semestral work with spring-boot and i am struggling about restController and his endpoints. I have controllers for users, teams, tasks, comments etc.

For example controller for teams has these endpoints: "/teams" - returns all teams "/teams/{idTeam}" - return specific team by id etc...

By my opinion these endpoints are fine, but what if i need return tasks for a specific team ? Should be this endpoint look like "/teams/{idTeam}/tasks" in team controller, or "/tasks/teams/{idTeam}" in task controller. There is problem that i dont know whether is good practice that controller for teams returns also something else than just team objects... example returns also tasks in team or comments...

Btw. The team entity has array of tasks or comments in itself, but i annotated the arrays with @JsonIgnore because somebody who calls /teams/{idTeam} wants for example just name of the team, not all tasks, comments, users etc of the returned team - so its unnesesary downloading another amount of data.

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82
S3jp4kCZE
  • 15
  • 6

1 Answers1

1

Both options are possible. I would recommend beause tasks is a sub entity of teams

/teams/{idTeam}/tasks

There is a good article in the StackOverflow Blog: https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/

And this could also help http://microformats.org/wiki/rest/urls

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82
  • Thanks for answer, as most valuable for me seems this article: "The path of the endpoints that deal with nested resources should be done by appending the nested resource as the name of the path that comes after the parent resource. We have to make sure that it makes sure what we considered a nested resources matches what we have in our database tables. Otherwise, it’ll be confusing. For instance, if we want an endpoint to get the comments for a news article, we should append the /comments path to the end of the /articles path." – S3jp4kCZE Apr 23 '20 at 12:10
  • I'm happy to help. If my answer is helpful please accept it or up vote it. Thank you – Simon Martinelli Apr 23 '20 at 12:14