Reputation: 173
For a school project, I'm designing a RESTful API for managing restaurants and restaurant owners (restaurateurs)
There is a relation between restaurants and restaurateurs.
A restaurant can have one or zero restaurateurs and a restaurateur can have zero or more restaurants.
So far I have the following endpoints:
GET /api/restaurants
POST /api/restaurants
GET /api/restaurants/{id}
PUT /api/restaurants/{id}
DELETE /api/restaurants/{id}
GET /api/restaurants/{id}/restaurateur
GET /api/restaurateurs
POST /api/restaurateurs
GET /api/restaurateurs/{id}
PUT /api/restaurateurs/{id}
DELETE /api/restaurateurs/{id}
GET /api/restaurateurs/{id}/restaurants
GET /api/restaurateurs/{id}/restaurants/{restaurant-id}
Now I want to add the feature to link and unlink restaurants and restaurateurs
What I had in mind is this:
To link a restaurateur to a restaurant
POST /api/restaurants/{id}/restaurateur
Body: {"restaurateur_id": 99}
And
POST /api/restaurateurs/{id}/restaurants
Body: [99, 88, ...]
To unlink a restaurateur from a restaurant
DELETE /api/restaurants/{id}/restaurateur
And
DELETE /api/restaurateurs/{id}/restaurants/{restaurant-id}
Are those good RESTful solutions, and if not what would you recommend?
What are the best practices for this kind of problem?
Upvotes: 1
Views: 157
Reputation: 1095
If you REST API is for in-house applications, you can use the LINK and UNLINK HTTP verbs.
Upvotes: 1