inaka/Jayme

Add some extra typical CRUD operations

volbap opened this issue · 2 comments

The current read operations allow you to:

.findAll() // GET /entities , parse result as array of dictionaries
.find(byId: id) // GET /entities/:id , parse result as dictionary

It would be useful to also have these methods:

.find() // GET /entity , parse result as dictionary
.find(byId: id, subpath: "subentity") // GET /entities/:id/subentity

Some example scenarios where these methods are useful:

  • GET /me
  • GET /devices/:id/users
  • GET /devices/:id/messages

So, this is the scenario we want to cover:

Single-Entity RepositoryMultiple-Entity Repository
CREATEPOST /me → ⚪ POST /users → ⚪
POST /users → [⚪ ,⚪ , ...]
READGET /me → ⚪ GET /users/:id →⚪
GET /users → [⚪ ,⚪ , ...]
UPDATEPUT /me → ⚪PUT /users/:id → ⚪
PATCH /users → [⚪ ,⚪ , ...]
DELETEDELETE /meDELETE /users/:id

We haven't defined yet how we're going to organize the protocols to design a decent interface.


As for PATCH methods, where only a few fields need to be updated, and not the whole entity, it doesn't make sense to develop interfaces for them, because there is no simple way we could generate such interface, and because Jayme's design requires the object to be fully-loaded when using structs. We rather let users define these kind of interfaces on their own, based on their entities.


As for subpaths, we have decided not to include them as standard interfaces, because there might be many interpretations and posibilites, which can lead to confusion. We rather leave their definition up to the user. Examples:

GET /users/:id/session → ⚪
GET /users/:id/cars → [⚪ ,⚪ , ...]
GET /users/:id/cars/:car_id → ⚪
GET /users/:id/cars/:car_id/engine → ⚪
GET /users/:id/cars/:car_id/invoices → [⚪ ,⚪ , ...]

This is the final set of methods we've come up with:

Single-Entity Repository
(e.g. /profile)
Multiple-Entity Repository
(e.g. /users)
Creatable.create(e)
POST /profile → ⚪
.create(e)
POST /users → ⚪

.create([e1, e2, ...])
POST /users → [⚪ ,⚪ , ...]
Readable.read()
GET /profile → ⚪
.read(id: x)
GET /users/x →⚪

.readAll()
GET /users → [⚪ ,⚪ , ...]
Updatable.update(e)
PUT /profile → ⚪
.update(e, id: x)
PUT /users/x → ⚪

.update([e1, e2, ...])
PATCH /users → [⚪ ,⚪ , ...]
Deletable.delete()
DELETE /profile
.delete(id: x)
DELETE /users/x