Skip to content

Support relations when generating REST handlers #56

@kettanaito

Description

@kettanaito

GitHub

What

Given the following model declarations:

const db = factory({
  user: {
    id: primaryKey(String),
    posts: manyOf('post')
  },
  post: {
    slug: primaryKey(String)
  }
})

And called db.user.toHandlers, the following relation handlers must be created in addition to the default CRUD handlers:

  • GET /users/:id/posts, returns all posts that belong to the user.
  • GET /users/:id/posts/:slug, returns a post by a slug that belongs to the user.

I'd say that PUT and DELETE methods shouldn't be nested in this way, forcing you to update/delete a post instance directly (i.e. PUT /posts/:slug).

Questions

  • Should oneOf relations pluralize the model name in the handler URL?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions