Currently, we are manually creating each and every endpoint for each model. Then, if there is a ManyToMany relationship within a model, and we manually create a nested endpoint. For example, to get the friends of a given User, we manually created the endpoint /api/users/<user_id>/friends.
The DRF Nested Routers package provides routers that allow you to easily create nested routes for your API, without manually creating every endpoint. You can use it to create nested routes for all the attributes in a model. This would not only shorten the code, but also create a more exhaustive list of endpoints for the API
Currently, we are manually creating each and every endpoint for each model. Then, if there is a
ManyToMany
relationship within a model, and we manually create a nested endpoint. For example, to get thefriends
of a givenUser
, we manually created the endpoint/api/users/<user_id>/friends
.The
DRF Nested Routers
package provides routers that allow you to easily create nested routes for yourAPI
, without manually creating every endpoint. You can use it to create nested routes for all the attributes in a model. This would not only shorten the code, but also create a more exhaustive list of endpoints for theAPI