Expand description
§rust-web-server
A static file web server and HTTP toolkit written in Rust. Supports HTTP/3 (QUIC), HTTP/2, and HTTP/1.1.
§Use as a library
Add to Cargo.toml:
[dependencies]
rust-web-server = "17"§Quick start: add a custom route
use rust_web_server::controller::Controller;
use rust_web_server::request::{METHOD, Request};
use rust_web_server::response::{Response, STATUS_CODE_REASON_PHRASE};
use rust_web_server::range::Range;
use rust_web_server::mime_type::MimeType;
use rust_web_server::server::ConnectionInfo;
pub struct PingController;
impl Controller for PingController {
fn is_matching(request: &Request, _: &ConnectionInfo) -> bool {
request.method == METHOD.get && request.request_uri == "/ping"
}
fn process(_: &Request, mut response: Response, _: &ConnectionInfo) -> Response {
response.status_code = *STATUS_CODE_REASON_PHRASE.n200_ok.status_code;
response.reason_phrase = STATUS_CODE_REASON_PHRASE.n200_ok.reason_phrase.to_string();
response.content_range_list = vec![
Range::get_content_range(b"pong".to_vec(), MimeType::TEXT_PLAIN.to_string())
];
response
}
}See DEVELOPER.md for the full building blocks reference and use case examples.
Modules§
- app
- application
- async_
state - Async-capable state-aware application — requires the
http2feature (tokio). - blocklist
- Runtime IP blocklist middleware.
- body
- cache
- In-memory response cache middleware.
- canary
- Weighted canary / A-B traffic splitting middleware.
- circuit_
breaker - Circuit breaker state machine and retry middleware.
- client_
hint - compression
- config_
binding - Typed configuration binding — read environment variables into strongly-typed structs.
- config_
reload - Hot configuration reload.
- controller
- cookie
- core
- cors
- di
- Lightweight type-keyed dependency injection container.
- entry_
point - error
- ext
- extract
- feature
- Runtime feature toggles.
- header
- http
- http_
client - Outbound HTTP/1.1 client.
- ingress
- Kubernetes Ingress watcher and router.
- ip_
filter - IP address allowlist and denylist middleware.
- json
- language
- log
- macros
- Declarative routing macro.
- maintenance
- Maintenance mode middleware.
- mcp
- Model Context Protocol (MCP) server — HTTP Streamable HTTP transport.
- metrics
- Server-wide and per-route Prometheus metrics.
- middleware
- Composable middleware pipeline.
- mime_
type - null
- otel
- OpenTelemetry-compatible distributed tracing.
- prelude
- Convenience re-exports for writing handlers and running the server.
- proxy
- Reverse proxy middleware with round-robin load balancing.
- proxy_
config - Config-driven proxy application.
- range
- rate_
limit - request
- request_
log - In-memory ring buffer of recent HTTP requests.
- response
- rewrite
- Request and response rewriting middleware.
- router
- scheduler
- Background task scheduler — a
@Scheduled-style runner for fixed-rate, fixed-delay, and cron-expression tasks. - server
- server_
config - Typed server configuration.
- service_
discovery - Dynamic backend pool with pluggable discovery sources.
- session
- Server-side session management.
- sse
- Server-Sent Events (SSE) response builder.
- state
- Shared application state and state-aware routing.
- symbol
- tcp_
proxy - Layer-4 TCP proxy.
- test_
client - thread_
pool - udp_
proxy - Layer-4 UDP proxy.
- url
- validate
- virtual_
host - websocket
- WebSocket protocol support — RFC 6455.
- ws_
proxy - WebSocket reverse proxy.
Macros§
- routes
- Build a routing app from a declarative table.