Skip to content

API Reference

Full rustdoc documentation is published at docs.rs/rust-web-server.

This page is a quick-reference index — click through to docs.rs for the complete method-level API.

Application layer

Type / TraitModuleDescription
AppappZero-config application with all built-in controllers enabled
AppWithState<S>stateState-aware app with .get/.post/.put/.patch/.delete route builders
AsyncAppWithState<S>async_stateAsync handler variant — requires http2 feature
WithMiddleware<A>middlewareWraps any Application with a layered middleware stack
McpServermcpMCP Streamable HTTP server (JSON-RPC 2.0 over POST /mcp)
ApplicationapplicationTrait implemented by all app types: execute(&Request, &ConnectionInfo) -> Result<Response, String>

HTTP primitives

Type / TraitModuleDescription
RequestrequestParsed HTTP request: method, URI, version, headers, body bytes
ResponseresponseHTTP response: status code, headers, body as Vec<ContentRange>
HeaderheaderName/value pair; constants for all standard header names
MimeTypemime_typeMIME type string constants
Range / ContentRangerangeBody content-range helpers used by Response

Routing

Type / TraitModuleDescription
RouterrouterPath-pattern router with :param named segments and *wildcard
PathParamsrouterExtracted path parameters; .get(name) -> Option<&str>
ConnectionInfoserverClient/server IP, port, and SNI hostname per connection

Server

Type / TraitModuleDescription
ServerserverTCP listener, thread pool, TLS acceptor, and request loop

Middleware

Type / TraitModuleDescription
RateLimiterrate_limitSliding-window per-key rate limiter; rate_limit::global() for the singleton
CacheLayercacheIn-memory TTL response cache
MetricsLayermetricsPer-route Prometheus counters and latency histograms
OtelLayerotelW3C traceparent propagation and OTLP span export
RewriteLayerrewriteRequest/response header, URI, body, and status rewriting
BasicAuthLayerauthHTTP Basic authentication middleware
JwtLayerauthHS256 Bearer JWT validation middleware
IpFilterip_filterIP address allowlist or denylist middleware
CsrfLayercsrfCSRF double-submit cookie protection middleware
OidcAuthssoOAuth2 / OIDC SSO integration middleware
CanaryLayercanaryWeighted traffic splitting (canary deployments)
CircuitBreakercircuit_breakerCircuit breaker state machine (closed / open / half-open)

Proxy

Type / TraitModuleDescription
ReverseProxyproxyHTTP/1.1 reverse proxy middleware
H2ReverseProxyproxyHTTP/2 upstream reverse proxy middleware (http2 feature)
GrpcProxyproxygRPC proxy (wraps H2ReverseProxy, filters on application/grpc*)
TcpProxytcp_proxyStandalone L4 TCP proxy with round-robin backend selection
UdpProxyudp_proxyStandalone UDP datagram proxy
WsProxyws_proxyWebSocket proxy with bidirectional byte relay
BackendPoolservice_discoveryDynamic backend pool with periodic refresh

Real-time protocols

Type / TraitModuleDescription
Sse / SseEventsseServer-Sent Events builder
WebSocketwebsocketWebSocket handshake and frame codec

Database / ORM

Type / TraitModuleDescription
DbPoolmodelPre-created connection pool with Mutex<Vec<DbConnection>>
DbConnectionmodelSingle database connection for SQLite, PostgreSQL, or MySQL
Repository<T, ID>modelCRUD repository trait (find_by_id, save, delete, …)
QueryBuilder<T>modelFluent query builder with where_eq, fetch_all, count, etc.

Sessions

Type / TraitModuleDescription
SessionStoresessionIn-memory TTL session store keyed by a session ID string

Infrastructure

Type / TraitModuleDescription
TestClienttest_clientIn-process test client — dispatches requests without a TCP socket
ContainerdiTypeId-keyed dependency injection container
SchedulerschedulerBackground task scheduler for recurring or one-off jobs
KubernetesIngressWatcheringressPolls the Kubernetes API for Ingress resources and maintains a live route table

Typed extractors and errors

Type / TraitModuleDescription
BodyextractRaw request body bytes (never fails)
BodyTextextractUTF-8 request body (returns 400 on invalid UTF-8)
QueryextractParsed query string as HashMap<String, String>
RequestHeadersextractAll request headers with case-insensitive .get(name)
IntoResponseerrorTrait for mapping error enums to Response values
AppErrorerrorBuilt-in error variants: BadRequest, NotFound, Internal, etc.