Skip to content

Commit

Permalink
Support multi-segment and empty API prefixes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbearer committed May 1, 2024
1 parent b17eacc commit 9416c14
Show file tree
Hide file tree
Showing 4 changed files with 671 additions and 124 deletions.
Loading

0 comments on commit 9416c14

Please sign in to comment.