Skip to main content

rust_web_server/
lib.rs

1//! # rust-web-server
2//!
3//! A static file web server and HTTP toolkit written in Rust.
4//! Supports HTTP/3 (QUIC), HTTP/2, and HTTP/1.1.
5//!
6//! ## Use as a library
7//!
8//! Add to `Cargo.toml`:
9//!
10//! ```toml
11//! [dependencies]
12//! rust-web-server = "17"
13//! ```
14//!
15//! ## Quick start: add a custom route
16//!
17//! ```rust,no_run
18//! use rust_web_server::controller::Controller;
19//! use rust_web_server::request::{METHOD, Request};
20//! use rust_web_server::response::{Response, STATUS_CODE_REASON_PHRASE};
21//! use rust_web_server::range::Range;
22//! use rust_web_server::mime_type::MimeType;
23//! use rust_web_server::server::ConnectionInfo;
24//!
25//! pub struct PingController;
26//!
27//! impl Controller for PingController {
28//!     fn is_matching(request: &Request, _: &ConnectionInfo) -> bool {
29//!         request.method == METHOD.get && request.request_uri == "/ping"
30//!     }
31//!
32//!     fn process(_: &Request, mut response: Response, _: &ConnectionInfo) -> Response {
33//!         response.status_code = *STATUS_CODE_REASON_PHRASE.n200_ok.status_code;
34//!         response.reason_phrase = STATUS_CODE_REASON_PHRASE.n200_ok.reason_phrase.to_string();
35//!         response.content_range_list = vec![
36//!             Range::get_content_range(b"pong".to_vec(), MimeType::TEXT_PLAIN.to_string())
37//!         ];
38//!         response
39//!     }
40//! }
41//! ```
42//!
43//! See [DEVELOPER.md](https://github.com/bohdaq/rust-web-server/blob/main/DEVELOPER.md)
44//! for the full building blocks reference and use case examples.
45
46// Allows `::rust_web_server::…` paths to resolve from within this crate's own
47// tests, which is required by proc-macro derive output that uses that prefix.
48extern crate self as rust_web_server;
49
50pub mod app;
51#[cfg(feature = "auth")]
52pub mod auth;
53
54#[cfg(feature = "macros")]
55pub use rws_macros::{delete, get, patch, post, put, route, Config, FromRequest, Validate};
56#[cfg(all(feature = "macros", any(feature = "model-sqlite", feature = "model-postgres", feature = "model-mysql")))]
57pub use rws_macros::Model;
58#[cfg(feature = "http2")]
59pub mod async_state;
60pub mod session;
61pub mod sse;
62pub mod compression;
63pub mod cookie;
64pub mod error;
65pub mod extract;
66pub mod ip_filter;
67pub mod macros;
68pub mod blocklist;
69pub mod cache;
70pub mod config_reload;
71pub mod feature;
72pub mod maintenance;
73pub mod metrics;
74pub mod mcp;
75pub mod request_log;
76pub mod otel;
77#[cfg(feature = "acme")]
78pub mod acme;
79pub mod middleware;
80pub mod rate_limit;
81pub mod router;
82pub mod state;
83pub mod test_client;
84pub mod application;
85pub mod body;
86pub mod client_hint;
87pub mod controller;
88pub mod core;
89pub mod cors;
90pub mod entry_point;
91pub mod ext;
92pub mod header;
93pub mod http;
94pub mod json;
95pub mod language;
96pub mod log;
97pub mod mime_type;
98pub mod null;
99pub mod range;
100pub mod request;
101pub mod response;
102pub mod server;
103pub mod symbol;
104pub mod thread_pool;
105pub mod url;
106pub mod proxy;
107pub mod rewrite;
108pub mod scheduler;
109pub mod tcp_proxy;
110pub mod udp_proxy;
111pub mod ws_proxy;
112pub mod canary;
113pub mod circuit_breaker;
114pub mod service_discovery;
115pub mod config_binding;
116pub mod di;
117pub mod proxy_config;
118pub mod ingress;
119#[cfg(feature = "tera")]
120pub mod template;
121pub mod validate;
122pub mod virtual_host;
123#[cfg(any(feature = "model-sqlite", feature = "model-postgres", feature = "model-mysql"))]
124pub mod model;
125pub mod websocket;
126pub mod http_client;
127#[cfg(feature = "crypto")]
128pub mod crypto;
129#[cfg(feature = "csrf")]
130pub mod csrf;
131#[cfg(feature = "sso")]
132pub mod sso;
133pub mod prelude;
134
135#[cfg(feature = "http2")]
136#[doc(hidden)]
137pub mod tls;
138
139#[cfg(feature = "http2")]
140#[doc(hidden)]
141pub mod h2_handler;
142
143#[cfg(feature = "http3")]
144#[doc(hidden)]
145pub mod h3_handler;