photonic.bean photonic.bean - 3 years ago 196
reST (reStructuredText) Question

RESTful API URI design: hierarchy

Having the models shown below, where a User (admin) can have multiple Places, Places can be managed by multiple Users (non-admin), and Places can have many Tables, many Customers, Sections and so on:

--> Table
User <--> Place --> Customer
--> Section

Notation: <--> many to many
--> one to many


Is this RESTful API implementation well designed according the REST guidelines? I'm not sure whether should I implement the API using hierarchical levels or not.

REST API, including HTTP valid methods for each endpoint in between brackets:

/api/places [GET, POST]
/api/places/<name> [GET, PUT, DELETE]
/api/places/<name>/customers [GET, POST]
/api/places/<name>/customers/<id> [GET, PUT, DELETE]
/api/places/<name>/tables [GET, POST]
/api/places/<name>/tables/<id> [GET, PUT, DELETE]
/api/places/<name>/users [GET, POST]
/api/places/<name>/users/<username> [GET, PUT, DELETE]

Answer Source

REST does not have guidelines in terms of how your url hierarchy should be defined.

Your url design looks fine enough enough to give a human an idea of how your api is structured.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download