Expand description
HTTP transport for nestrs — a nest_rs_core::Transport backed by poem.
HttpTransport mounts every #[routes] controller, every self-mounting
endpoint another surface declares (a GraphQL schema, an MCP service — each
via HttpEndpointMeta), and any extra endpoint registered with
HttpTransport::mount.
Re-exports§
Modules§
- endpoint_
wrap_ priority - Canonical priority bands for transport-edge wraps, mirroring the documented HTTP wrap order (outermost → innermost):
Structs§
- Client
Ip - Best-effort client IP for the current request. Always present (see the module doc for the resolution order and the security caveat).
- Cors
Config - Cross-Origin Resource Sharing policy.
originsempty ⇒ no CORS layer installed (the default). Lists are comma-separated in env vars. - Ctx
- Extracts a request-scoped value of type
Tan upstream guard or interceptor attached. - Global
Guards Active - Marker provided by
use_guards_globalwhen at least one global guard is registered. The transport reads it (it cannot see theGuardtrait orGuardSpecs) to decide whether an unguardable endpoint — an imperativemount(...)the transport can neither shape nor introspect — is a fail-secure violation. - Http
Boot Check - A boot-time check the HTTP transport runs at the start of
configure. ReturningErr(message)aborts boot with that message. - Http
Config - HTTP transport options resolved at boot. Every field is settable both via
NESTRS_HTTP__*env vars (read byConfig::from_env) and via the pinned struct (passed toHttpModule::for_root). - Http
Controller Meta - Discovery metadata attached to every
#[controller]+#[routes]type.crate::HttpTransportiterates these at boot vianest_rs_core::DiscoveryService::meta; apps can read the same metadata to drive secondary concerns (OpenAPI rendering, route listings). - Http
Endpoint Meta - Discovery metadata for a self-mounting HTTP endpoint owned by another
surface (a GraphQL schema, an MCP streamable-HTTP service). The closure
nests one opaque sub-endpoint at its own path;
pathandlabelexist only so the transport can list the mount in its boot-time route log. - Http
Endpoint Wrap - Discovery metadata attached at boot. The HTTP transport collects every
HttpEndpointWrapatconfiguretime, sorts bypriority(), and folds them around the assembled route (after per-route layers, before CORS / server header). - Http
Module - Http
Route Meta - Declarative description of a handler in a controller — verb/path/name plus
the OpenAPI facets
#[routes]extracts, so a doc generator (nestrs-openapi) builds a spec from discovery alone. - Http
Setup - Http
Transport - HTTP
Transportbacked by poem. AtTransport::configuretime, runs every discoveredHttpBootCheck, mounts every#[module(providers = [...])]-declaredHttpControllerMetaandHttpEndpointMeta, then any imperativeHttpTransport::mount, then folds every discoveredHttpEndpointWrapwrap around the assembled endpoint. Transport-edge wraps (the global interceptor / filter pools, infra#[interceptor]s likeDbContext) attach themselves throughHttpEndpointWrapfrom their own crates — this transport stays free of the cross-transport trait crates and only knows about poem. Guards and pipes never wrap here: they execute in the per-route shaper (post-routing) or at aGuardedself-mount’s edge. - Piped
- Applies pipe
Pto the value extractorEproduces, handing the handler the transformedP::Out. - Problem
Details - Body of an
application/problem+jsonresponse. Stable URIs for the well-known constructors live athttps://www.rfc-editor.org/rfc/rfc9457—typeis the only field a client may key on, so the URIs are stable across releases (and overridable viawith_typewhen an app wants to publish its own type registry). - RawBody
- Whole request body as
Bytes, bounded byRawBody::DEFAULT_LIMIT(or by theRawBodyLimitin the request extensions, when installed). - RawBody
Limit - Per-request byte cap for
RawBody, read from the request extensions.HttpModuleinstalls this fromHttpConfig.max_body_bytes; absent ⇒ the extractor falls back toRawBody::DEFAULT_LIMIT. Public so middleware can pin a per-route cap by inserting it intoreq.extensions_mut(). - Reflector
- Request
Scope Endpoint - Installs a fresh
RequestScope(over the singleton container) into each request’s extensions before delegating inward, so guards and handlers can resolve request-scoped providers viaScoped<T>. Applied outermost byHttpTransport. - Scoped
- Resolves a provider of type
Tfrom the current request’sRequestScope. Rejects with500if the scope is absent (a transport wiring bug) or if no provider is registered forT. - Self
Mount Guard Wrap - Discovery metadata that wraps a single
EdgePosture::Guardedself-mount with the global guard chain. Provided bynest-rs-guards’use_guards_global(which can see theGuardtrait); applied by the HTTP transport, which cannot — the closure keeps this crate free of any guard dependency, the same inversionHttpEndpointWrapuses. Absent when no global guard is registered, in which case guarded self-mounts mount unwrapped. - Shaped
Endpoint - TlsConfig
- TLS material for the HTTP transport: a PEM certificate chain and private
key, handed to
HttpTransport::tls. - Valid
- Validation pipe: extract
E, validate withvalidator::Validate, reject invalid input with a field-level JSON400.Valid<Json<T>>is the ergonomic form ofPiped<ValidationPipe<T>, Json<T>>.
Enums§
- Edge
Posture - How a self-mounted endpoint relates to the global guard pool.
- Http
Verb
Traits§
- Controller
- Implemented automatically by the
#[routes]macro. Each controller mounts its routes (prefixed with the controller’sPATH) onto a parentRoute. - Into
Inner - Owned-unwrap for poem extractors, so a pipe can take the value they carry without cloning.
- Route
Response Shaper - A handler wrapper keyed by a marker type.
#[routes]applies it when a handler declares a parameter of an implementing type.
Functions§
- join_
path - Join a controller prefix with a route path the way poem’s nesting does:
("/health", "/live") -> "/health/live". Public sonestrs-openapicomposes paths identically to how this transport mounts them — the served path and the documented path must not drift. - schema_
of - Kept here so
#[routes]emits::nest_rs_http::schema_of::<T>and never namesschemars’ generator API itself. - shaped
- version_
path - Apply URI API versioning:
Some("1"), "/users"→"/v1/users". The single place the URI strategy lives —#[routes], the boot route log, and the OpenAPI document all route through it so the served/logged/documented paths can never drift.
Type Aliases§
- Schema
Fn - Builds the schema for a
Json<T>request body or response, recording named component schemas in the shared generator.#[routes]emits one per JSON payload it finds; a non-Json<…>body/return carriesNoneand imposes noJsonSchemabound.
Attribute Macros§
- async_
trait - controller
#[controller(path = "/health")]— paired with#[routes]on the impl block. Generatesfrom_container(&Container) -> Selfand apub const PATH.- crud
- Generate standard REST operations (list/get/create/update/delete) on a
#[controller]impl block, re-emitting under#[routes]. Grammar:#[crud(entity = …::Entity, output = Dto, create = CreateDto, update = UpdateDto, readonly, paginate = cursor|page)]. - http_
code #[http_code(N)]— override the response status (100..=999). Passthrough marker consumed by#[routes]. Mutually exclusive with#[redirect].- input
#[input]— shorthand for input DTOs. Appends#[derive(::serde::Deserialize, ::validator::Validate)]and#[serde(deny_unknown_fields)]so an unknown field on the wire (e.g.is_admin: true) is rejected at parse time instead of silently dropped.- interceptor
- Mark a struct as a global HTTP interceptor. Behaves like
#[injectable]for construction and additionally emits aDiscoverableimpl attaching anHttpEndpointWrap; the HTTP transport reads those metas at boot. The struct must implementnest_rs_interceptors::Interceptor. - redirect
#[redirect("url"[, code])]— discard the handler’s payload and return a redirect. Status defaults to307and must be in300..=399. Mutually exclusive with#[http_code]. The decorated method’s body must be empty —#[routes]does not call it. Passthrough marker consumed by#[routes].- response_
header #[response_header("name", "value")]— append a header to the response. Stacks with#[http_code]and#[redirect]; repeatable. Passthrough marker consumed by#[routes].- routes
- Bind controller methods to HTTP routes. Applied to an
implblock belonging to a#[controller]-marked struct. Each method tagged with#[get("/path")],#[post],#[put],#[delete], or#[patch]is wired as a poem handler.