Support multi-segment and empty API prefixes #220
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andstate/blocks/:height/index
, which look like two different endpoints instate
module, but are actually two separate modules,state/fee
andstate/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