Expand description
Axum HTTP/JSON API handlers
ModulesΒ§
StructsΒ§
- ApiJson π
- Successful JSON response for v1 handlers, most of which return domain types (from
espresso-types,hotshot-query-service, etc.) that donβt implementschemars::JsonSchema; this crate doesnβt add OpenAPI derives to domain types. Wire format is identical toaxum::Json<T>; only the OpenAPI operation gets an untyped 200 response instead of a generated schema. - Custom
Error π - Error
Response π - API error response, wire-compatible with the
Customvariant of the per-module error enums (node::Error::Custom,merklized_state::Error::Custom, etc.) that all of tide-discoβsError::catch_allcalls produce. Most of our migrated endpoints (catchup, submit, state-signature, light-client, node, status, config, token, database) take that path, so this envelope is byte-identical with tideβs error response for them. Endpoints that use a specific variant directly (e.g.availability::Error::FetchLeaf) emit their own shape on tide; those bytes are not matched here. - Open
ApiV1 π - Wrapper so the v1 spec is looked up by a distinct type. v2 serves a build-time document
rather than an
Extension<OpenApi>, so nothing collides today, but the newtype keeps anExtension<OpenApi>added later from silently resolving to v1βs. - Request
Limit π - In-flight request slots for
max_connections.
FunctionsΒ§
- create_
router_ v1 - Create v1 router with OpenAPI documentation.
- declare_
path_ πtemplate_ parameters - decode_
body π - Decode a request body based on its
Content-Type, matched by media-type essence. - encode_
response π - Encode a successful response body based on the requestβs
Acceptheader, matching tide-discoβs content negotiation. - finish_
v1_ docs - Build the OpenAPI spec for the mounted routes and attach the docs routes; every serve mode must route through this.
- healthcheck π
- limit_
requests π - Each request holds a slot while in flight; excess gets 429. A websocketβs slot is released at the 101 upgrade: long-lived streams are deliberately unbounded here, since demo workloads (nasty-client holds hundreds of streams by design) dwarf the request budget of 25.
- module_
healthcheck π /v1/{module}/healthcheck, reached by legacy clients via the/{module}/healthcheckrewrite.- path_
parameter_ πschema - Types read off the handlersβ
Path<T>extractors; unknown names are strings. - redirect_
to_ πdocs - v2 is WIP, so
/points at the v1 docs; 307 so browsers donβt cache the redirect. - rewrite_
legacy_ πuri - Tide-disco served every v1 module at both
/<module>/...and/v1/<module>/..., and legacy clients (surf-disco, the light-client, tests) still address the unversioned and/v0forms. Axum only declares the/v1/...and/v2/...route shapes, andRouter::layermiddleware runs after routing, so it can never redirect a request onto a route it doesnβt already match. This function is instead wrapped around the whole router withtower::util::MapRequestLayer(seeserve_axum), which runs before routing, to rewrite the URI so the declared routes match. - router_
availability π - router_
block_ πstate - router_
catchup π - router_
config π - router_
database π - router_
explorer π - router_
fee_ πstate - router_
hotshot_ πevents - router_
light_ πclient - router_
node π - router_
reward π - router_
state_ πsignature - router_
status π - router_
submit π - router_
token π - router_
v2_ docs - Serve the v2 API documentation: the build-time OpenAPI document and the two UIs that render
it. Unlike
finish_v1_docs, nothing here inspects the router, so a route that is generated but never mounted would still appear in the document;v2_documented_routes_are_mountedasserts that never ships. - serve_
openapi_ πspec_ v1 - Serve the v1 OpenAPI spec (extracted from Extension)
- swagger_
html π - Serve custom Swagger UI with collapsed defaults, pointed at the given OpenAPI spec route.
- tag_
operations_ πby_ module - Declare a path parameter for every
{name}template segment of every operation. - v2_
error_ πenvelope - Give framework-level rejections on the v2 routes the same error envelope as handler errors.
- version π
- Tide-disco-compatible version response. Tide emits the binaryβs clap version; we emit the
crate version so
http_client::Client::connectand similar polling helpers succeed. - with_
top_ πlevel_ routes - Add the routes that every mode serves regardless of which API modules are enabled:
/,/healthcheck,/v1/healthcheck,/v2/healthcheck,/v1/{module}/healthcheck, and/version. Callers apply CORS.