I base my question on How to handle many-to-many relationships in a RESTful API? but I want to continue with the accepted answer.
Assume that there is a many-to-many relationship between players and teams (as in the question mentioned above).
As I understand it, there are several options for modeling this using REST resources:
The payload contains links to related resources.
GET /players/john
gives
{
"name": "John",
"_links": [
{
"rel": "team",
"href": "/teams/1"
},
{
"rel": "team",
"href": "/teams/4"
}
]
}
and
GET /teams/1
gives
{
"name": "Team 1",
"_links": [
{
"rel": "player",
"href": "/players/john"
},
...
]
}
, . , , . " " API RESTful?:
, URL/player/5/teams/
/1 , "" , " 1".
GET /teams/1
{
"name": "Team 1",
}
GET /players/john
{
"name": "John",
}
,
GET /relationships
[
{
"_links": [
{
"rel": "player",
"href": "/players/john"
},
{
"rel": "team",
"href": "/teams/1"
}
]
},
...
]
, , , . /players/john, ? , , , . , , , API.
, , "" , . ( ), - "" " 1".
GET /teams/1/players
-
{
"_links": [
{
"rel": "player",
"href": "/players/john"
},
...
]
}
GET /players/john/teams
-
{
"_links": [
{
"rel": "team",
"href": "/teams/1"
},
...
]
}
- , URL- ( )
, ?
"" REST?
contstraint, " " API RESTful?:
, URL/player/5/teams/
!