When presenting data models via the RESTful interface, it is understood the creation of top-level endpoints that are associated with a type / group of objects:
We can reuse HTTP verbs to activate actions on these groups (GET to list, POST to create, etc.). And when you imagine a model with a βdependencyβ (since it cannot exist without a βparentβ), we can create deeper endpoints to represent this dependency relationship:
- / users / [: identifier] / tokens
In this case, it makes sense not to have a top-level endpoint /tokens, since they cannot exist without a user.
Many-to-many relationships are becoming more complex. If two models can have many-to-many relationships, but can also really exist on their own, it makes sense to give both objects a top-level endpoint and a deeper endpoint to define this relationship:
- of users
- / cars
- / users / [: identifier] / cars
- / Cars / [: identifier] / users
Then we can use the PUT and DELETE methods to determine these relationships through the HTTP: interface PUT /users/[:user_id]/cars/[:car_id]. It makes sense that performing this PUT operation would create a data model that somehow connects two objects (for example, a connection table in a relational database).
, .
GET (GET /users/[:user_id]/cars/[:car_id])? , "" GET /cars/[:id]?
, , " " ? ?
, , , ? ? , REST , , ? - ?
Pls.: P ( , )