micro_web/
lib.rs

1//! High-level web framework built on top of micro-http.
2//!
3//! This crate provides an ergonomic web framework that simplifies building HTTP services
4//! by offering high-level abstractions while leveraging the efficient HTTP implementation
5//! from the micro-http crate.
6//!
7//! # Core Features
8//!
9//! - **Ergonomic Request Handling**
10//!   - Async function handlers with automatic type conversion
11//!   - Flexible routing with path parameters
12//!   - Built-in support for common data formats (JSON, form data, etc.)
13//!
14//! - **Middleware System**
15//!   - Composable request/response transformations
16//!   - Built-in middleware for common tasks (compression, date headers, etc.)
17//!   - Easy to implement custom middleware
18//!
19//! - **Type-Safe Extractors**
20//!   - Automatic request data extraction into Rust types
21//!   - Support for headers, query parameters, and request bodies
22//!   - Custom extractor implementation possible
23//!
24//! - **Flexible Response Types**
25//!   - Automatic conversion of Rust types to HTTP responses
26//!   - Streaming response support
27//!   - Content negotiation and compression
28//!
29//! # Architecture
30//!
31//! The framework is organized into several key modules:
32//!
33//! - **Core Types** ([`handler`], [`request`], [`responder`])
34//!   - Request handling traits and implementations
35//!   - Context types for accessing request data
36//!   - Response generation utilities
37//!
38//! - **Routing** ([`router`])
39//!   - URL pattern matching
40//!   - HTTP method filtering
41//!   - Route parameter extraction
42//!
43//! - **Data Extraction** ([`extract`])
44//!   - Query string parsing
45//!   - Form data handling
46//!   - JSON serialization/deserialization
47//!
48//! - **Request Filtering** ([`filter`])
49//!   - Header-based filtering
50//!   - Method matching
51//!   - Custom filter implementation
52//!
53//! - **Middleware** ([`wrapper`])
54//!   - Response transformation
55//!   - Cross-cutting concerns
56//!   - Built-in middleware components
57//!
58//! # Example
59//!
60//! ```no_run
61//! use micro_web::{
62//!     router::{get, Router},
63//!     Server,
64//! };
65//!
66//! // Define a simple handler
67//! async fn hello_world() -> &'static str {
68//!     "Hello, World!"
69//! }
70//!
71//! #[tokio::main]
72//! async fn main() {
73//!     // Create a router
74//!     let router = Router::builder()
75//!         .route("/", get(hello_world))
76//!         .build();
77//!
78//!     // Start the server
79//!     Server::builder()
80//!         .router(router)
81//!         .bind("127.0.0.1:3000")
82//!         .build()
83//!         .unwrap()
84//!         .start()
85//!         .await;
86//! }
87//! ```
88//!
89//! # Relationship with micro-http
90//!
91//! This framework builds upon the low-level HTTP implementation provided by micro-http:
92//!
93//! - micro-http handles the raw TCP connections and HTTP protocol details
94//! - This crate provides the high-level abstractions for building web services
95//! - The integration is seamless while maintaining performance
96//!
97//! See the [micro-http documentation](micro_http) for more details about the underlying implementation.
98
99// Internal modules
100mod body;
101mod fn_trait;
102mod handler;
103mod request;
104mod server;
105
106// Public modules
107pub mod date;
108pub mod encoding;
109pub mod extract;
110pub mod responder;
111pub mod router;
112
113// Public re-exports
114pub use body::OptionReqBody;
115pub use body::ResponseBody;
116pub use fn_trait::FnTrait;
117pub use handler::FnHandler;
118pub use handler::handler_fn;
119pub use request::PathParams;
120pub use request::RequestContext;
121pub use server::Server;