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//! handler_fn,
64//! Server,
65//! };
66//!
67//! // Define a simple handler
68//! async fn hello_world() -> &'static str {
69//! "Hello, World!"
70//! }
71//!
72//! #[tokio::main]
73//! async fn main() {
74//! // Create a router
75//! let router = Router::builder()
76//! .route("/", get(handler_fn(hello_world)))
77//! .build();
78//!
79//! // Start the server
80//! Server::builder()
81//! .router(router)
82//! .bind("127.0.0.1:3000")
83//! .build()
84//! .unwrap()
85//! .start()
86//! .await;
87//! }
88//! ```
89//!
90//! # Relationship with micro-http
91//!
92//! This framework builds upon the low-level HTTP implementation provided by micro-http:
93//!
94//! - micro-http handles the raw TCP connections and HTTP protocol details
95//! - This crate provides the high-level abstractions for building web services
96//! - The integration is seamless while maintaining performance
97//!
98//! See the [micro-http documentation](micro_http) for more details about the underlying implementation.
99
100// Internal modules
101mod body;
102mod fn_trait;
103mod handler;
104mod request;
105mod server;
106
107// Public modules
108pub mod responder;
109pub mod date;
110pub mod decorator;
111pub mod encoding;
112pub mod extract;
113pub mod router;
114
115// Public re-exports
116pub use body::OptionReqBody;
117pub use body::ResponseBody;
118pub use fn_trait::FnTrait;
119pub use handler::handler_fn;
120pub use handler::FnHandler;
121pub use request::PathParams;
122pub use request::RequestContext;
123pub use server::Server;