-
-
Notifications
You must be signed in to change notification settings - Fork 132
Open
Description
This relates to this discussion thread on Discord.
Is your feature request related to a problem? Please describe.
RestApiHandler only supports flat routes (/post, /post/42). There is no way to express parent-scoped access in the URL structure. To fetch only a user's posts, clients must manually filter by parent ID — which is error-prone and produces URLs that don't reflect the data hierarchy.
** Describe the solution you'd like **
Add explicit nested route configuration to RestApiHandler that enables hierarchical URL patterns (/user/:id/post, /user/:id/post/:postId) for all five HTTP methods, with automatic parent scoping enforced server-side:
new RestApiHandler({
schema: client.$schema,
endpoint: 'http://localhost/api',
nestedRoutes: {
User: {
Post: {
relation: 'author', // relation field on child pointing to parent
requireOrphanProtection: true, // optional: enforce safe onDelete at startup
},
},
},
});
Key behaviors:
- 404 if parent does not exist, or child does not belong to the requested parent.
- POST automatically binds the created child to the parent; returns 400 if the payload also sets that relation.
- Flat routes remain fully functional. Non-configured 3-segment paths fall through to fetchRelated unchanged.
- JSON:API self links in responses use the nested URL.
requireOrphanProtection: true throws at startup if the configured relation does not have onDelete: Cascade, Restrict, or NoAction in the schema.- All configuration errors (unknown models, missing relation fields, mismatched targets) are caught at construction time.
Describe alternatives you've considered
- Implicit route generation from schema relations (aka auto discovery of the route nesting) — rejected because it creates unexpected route surface area and is hard to audit. Explicit-only is safer.
- Client-side filtering via filter[authorId]=u1 on flat routes — works but is not server-enforced and doesn't produce hierarchical URLs.
Additional context
modelNameMappingandexternalIdMappingare both respected on nested routes.- Multi-level nesting (/a/:id/b/:id/c) could be done later.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels