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
46pub mod app;
47#[cfg(feature = "auth")]
48pub mod auth;
49
50#[cfg(feature = "macros")]
51pub use rws_macros::{delete, get, patch, post, put, route};
52#[cfg(feature = "http2")]
53pub mod async_state;
54pub mod session;
55pub mod sse;
56pub mod compression;
57pub mod cookie;
58pub mod error;
59pub mod extract;
60pub mod ip_filter;
61pub mod macros;
62pub mod metrics;
63pub mod middleware;
64pub mod rate_limit;
65pub mod router;
66pub mod state;
67pub mod test_client;
68pub mod application;
69pub mod body;
70pub mod client_hint;
71pub mod controller;
72pub mod core;
73pub mod cors;
74pub mod entry_point;
75pub mod ext;
76pub mod header;
77pub mod http;
78pub mod json;
79pub mod language;
80pub mod log;
81pub mod mime_type;
82pub mod null;
83pub mod range;
84pub mod request;
85pub mod response;
86pub mod server;
87pub mod symbol;
88pub mod thread_pool;
89pub mod url;
90pub mod websocket;
91
92#[cfg(feature = "http2")]
93#[doc(hidden)]
94pub mod tls;
95
96#[cfg(feature = "http2")]
97#[doc(hidden)]
98pub mod h2_handler;
99
100#[cfg(feature = "http3")]
101#[doc(hidden)]
102pub mod h3_handler;