Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[Feature Request] Automatic REST API: Support for Nested Resource Endpoints (Hierarchical Routing)

Open
#2,374 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
15/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
api

Research direction

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.

Written by the indexing model from the issue text.

Description

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 POST to /threads/1/comments should automatically associate the new comment with threadId: 1 without requiring the ID in the request body.
  • ZModel Configuration: Ideally, this could be defined in the .zmodel file 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:

Dominant language
TypeScript
Stars
2.9k
Forks
157
Avg merge
11h 42m
Merged PRs (30d)
20

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from zenstackhq/zenstack

All issues in zenstackhq/zenstack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.