Skip to content
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 multi-segment and empty API prefixes #220

Merged
merged 1 commit into from
May 2, 2024
Merged

Conversation

jbearer
Copy link
Member

@jbearer jbearer commented May 1, 2024

It is sometimes useful to have an API where different modules internally look like parts of the same module to clients. For example, in the sequencer we have state/fee/:height/:account and state/blocks/:height/index, which look like two different endpoints in state module, but are actually two separate modules, state/fee and state/blocks. For this, we need multi-segment API prefixes.

Separately, it is often desirable when a service has only one module to host that module at the root URL, instead of adding some dummy prefix like /api. For this, we need empty API prefixes.

This change generalizes API dispatching to sequences of path segments rather than singular path segments, using a trie data structure to match (prefixes of) URL paths with API modules. We enforce that only the leaves of this trie contain actual data; in other words, it is disallowed, for clarity's sake, to have an API module whose path is a prefix of a different module.

Closes #211

It is sometimes useful to have an API where different modules internally
look like parts of the same module to clients. For example, in the
sequencer we have `state/fee/:height/:account` and `state/blocks/:height/index`,
which look like two different endpoints in `state` module, but are actually
two separate modules, `state/fee` and `state/blocks`. For this, we need
multi-segment API prefixes.

Separately, it is often desirable when a service has only one module to
host that module at the root URL, instead of adding some dummy prefix like
`/api`. For this, we need empty API prefixes.

This change generalizes API dispatching to sequences of path segments rather
than singular path segments, using a trie data structure to match (prefixes of)
URL paths with API modules. We enforce that only the leaves of this trie contain
actual data; in other words, it is disallowed, for clarity's sake, to have an
API module whose path is a prefix of a different module.
Copy link
Contributor

@nyospe nyospe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

src/app.rs Show resolved Hide resolved
src/dispatch.rs Show resolved Hide resolved
@jbearer jbearer merged commit a38837e into main May 2, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow module registered at root /
2 participants