1

I post the same unanswered question from a comment. Let's say I have 2 entities (Team and Player) and a many-to-many relationship (Registration) which have id_team and id_player fields but also others information like registrationDate.

GET /teams/{id}/players give me all players of a specific team

GET /players/{id}/teams give me all teams where a specific player is registred.

My first question is, can I create this resource : GET /teams/{id}/registrations ?

My second question is, what about if I want get ALL registrations ? can I access them by this URI : GET /registrations ?

Community
  • 1
  • 1
Antoine Martin
  • 1,903
  • 2
  • 16
  • 28
  • It depends on how your application server maps URLs to Java classes and how you register the REST URLs. But seriously, what's your code so far and what's your actual problem? – Smutje Feb 22 '15 at 13:25
  • I am beginer with AngularJS and I am still confused by how represent many-to-many relationships. This is a general question to know if it is common to access to a relationship by its own URI. – Antoine Martin Feb 22 '15 at 13:43
  • As you did not mention "AngularJS" in your question: How should anyone know? – Smutje Feb 22 '15 at 20:32

1 Answers1

1

I think you should use

/registrations/
/registrations/player:{pid}/
/registrations/team:{tid}/
/registrations/{rid}

So you should add a relationship resource and use flatten URI instead of creating a nested URI which is not so consistent if you want not just read, but modify this kind of resources.

note:

Btw. this is analogous to relationship tables by relational databases, so I guess the idea won't be so new to you.

inf3rno
  • 24,976
  • 11
  • 115
  • 197
  • Thank you. Do you think it is a good idea to use `/registration/player:{pid}/team:{tid}` and `/registration/team:{tid}/player:{pid}` if my database model has not id for registration ? – Antoine Martin Feb 24 '15 at 19:17
  • @AntoineMartin Ofc. you can use that kind of URI. – inf3rno Feb 24 '15 at 20:41