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, FromRequest, Validate};
56#[cfg(feature = "http2")]
57pub mod async_state;
58pub mod session;
59pub mod sse;
60pub mod compression;
61pub mod cookie;
62pub mod error;
63pub mod extract;
64pub mod ip_filter;
65pub mod macros;
66pub mod cache;
67pub mod config_reload;
68pub mod metrics;
69pub mod middleware;
70pub mod rate_limit;
71pub mod router;
72pub mod state;
73pub mod test_client;
74pub mod application;
75pub mod body;
76pub mod client_hint;
77pub mod controller;
78pub mod core;
79pub mod cors;
80pub mod entry_point;
81pub mod ext;
82pub mod header;
83pub mod http;
84pub mod json;
85pub mod language;
86pub mod log;
87pub mod mime_type;
88pub mod null;
89pub mod range;
90pub mod request;
91pub mod response;
92pub mod server;
93pub mod symbol;
94pub mod thread_pool;
95pub mod url;
96pub mod proxy;
97pub mod validate;
98pub mod websocket;
99
100#[cfg(feature = "http2")]
101#[doc(hidden)]
102pub mod tls;
103
104#[cfg(feature = "http2")]
105#[doc(hidden)]
106pub mod h2_handler;
107
108#[cfg(feature = "http3")]
109#[doc(hidden)]
110pub mod h3_handler;