[Feature Request] Automatic REST API: Support for Nested Resource Endpoints (Hierarchical Routing)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 15/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- typescript
- 领域
- api
调研方向
This is a design-level request with no pointer into the code: the payload names only ZenStack's automatic REST API, the .zmodel schema and the REST plugin configuration. Read how the REST plugin maps models to flat routes and how ZModel attributes are parsed, then weigh a schema attribute (the suggested @@http.path) against plugin config. "Done" means nested routes like GET /threads/1/comments that scope children to their parent, auto-set the foreign key on POST, and 404 on mismatch — but the approach needs maintainer agreement first.
由索引模型根据 Issue 内容生成。
描述
Description
Is your feature request related to a problem? Please describe.
Currently, ZenStack's automatic REST API generates "flat" endpoints for all models (e.g., /thread/1 and /comment/2). While functional, this doesn't reflect the logical ownership and hierarchy of data. For resources that are strictly dependent on a parent—such as a Comment that must always belong to a Thread—a flat structure lacks semantic clarity and forces the client to manually manage foreign keys in every request.
Without nested routing, the API doesn't express the constraint that a child resource's lifecycle is bound to its parent.
Describe the solution you'd like
I would like the ability to configure hierarchical or "nested" endpoints within the automatic REST API. This would allow for URLs like:
GET /threads/:threadId/comments/:commentId
Key Requirements:
- Logical Scoping: Accessing a child via a nested route should automatically apply a filter to ensure the child actually belongs to the specified parent.
- Simplified Creation: A
POSTto/threads/1/commentsshould automatically associate the new comment withthreadId: 1without requiring the ID in the request body. - ZModel Configuration: Ideally, this could be defined in the
.zmodelfile using an attribute (e.g.,@@http.path) or via the plugin configuration to specify parent-child relationships for routing.
Example Structure:
If a Thread has many Comments:
GET /threads/1/comments— Fetches all comments for thread 1.POST /threads/1/comments— Creates a comment specifically for thread 1.GET /threads/1/comments/2— Fetches comment 2, but only if it belongs to thread 1 (returning 404 otherwise).
Describe alternatives you've considered
- Flat Endpoints with Filters: Using
GET /comment?threadId=1. While this works, it is less RESTful and doesn't enforce the hierarchy at the routing level. - Custom Hooks/Routes: Writing manual Next.js or Express routes to wrap the ZenStack logic. This defeats the purpose of an "Automatic" REST API and increases boilerplate.
Additional context
Hierarchical routing is a staple of mature REST frameworks. For instance:
- Ruby on Rails allows
resources :threads do resources :comments end. - NestJS and Express developers frequently implement this to improve API discoverability and security through implicit scoping.
This feature would make ZenStack-generated APIs feel significantly more professional and "opinionated" in a way that aligns with standard REST best practices.
References:
- 主要语言
- TypeScript
- 星标
- 2.9k
- 派生
- 157
- 平均合并
- 2 天 46 分钟
- 30 天内合并 PR
- 17
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
zenstackhq/zenstack 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
zenstackhq/zenstack#2873 ·
维护者通常 1 天内回复
-
`@default` on a field of a `@map`-ed enum emits the enum name as the column default可能已有人在做 @jkugsiya 于 6 天前认领。 未关闭runtime
难度 2/5 1-3 小时 新手友好度 78/100
zenstackhq/zenstack#2868 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
zenstackhq/zenstack#2694 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 68/100
zenstackhq/zenstack#2659 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
zenstackhq/zenstack#2542 · 1 条评论 ·
维护者通常 1 天内回复
查看 zenstackhq/zenstack 的全部 Issue
相似的 Issue
-
check:failed streams:edit
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
package:ios ships XCFrameworks with absolute symlinks, which SwiftPM refuses to extract可能已有人在做 @cusnirvladislav 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
callstackincubator/rock#740 ·
-
S: triage
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
area:workflow bug ready-for-human
难度 1/5 1 小时以内 新手友好度 78/100
fil-donadoni/tolaria#6108 ·
维护者通常 1 天内回复