-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support relations when generating REST handlers #56
Comments
I think that for oneOf relations is good to have a singular noun. It makes the url self explanatory |
Makes perfect sense, @marcosvega91! |
The task is focused around the data/src/model/generateRestHandlers.ts Lines 132 to 154 in 3beed3f
We'd have to append additional handlers based on the model's relational properties (that should be available in the parsed model object). We need to watch out for circular model references when generating handlers: factory({
user: { id: primaryKey(String), friends: manyOf('user') }
})
// GET /user/:id/friends
// GET /user/:id/friends/:id
// GET /user/:id/friends/:id/friends/... It'd be great to generate the handlers for the referenced models standalone, and reference them in the nested paths of the current model. This once again suggests that we need access to the entire dictionary when generating handlers for a single model (also an issue I've encountered when working on #110). This may be a great time to enable this by extending the arguments of the |
FYI: I'm working on this. |
GitHub
What
Given the following model declarations:
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
oneOf
relations pluralize the model name in the handler URL?The text was updated successfully, but these errors were encountered: