Expand description
§HwhKit
一个用于快速构建 Web 服务的 Rust 工具库,支持前后端分离和不分离两种架构。
§特性
- 🚀 一键构建 Web 服务
- 🔧 灵活的中间件系统
- 📝 支持模板渲染(前后端不分离)
- 🌐 支持 API 服务(前后端分离)
- ⚙️ 基于配置的中间件装载
§快速开始
use hwhkit::WebServerBuilder;
#[tokio::main]
async fn main() {
let app = WebServerBuilder::new()
.config_from_file("config.toml")
.build()
.await
.expect("Failed to build server");
app.serve().await;
}
Re-exports§
pub use builder::WebServerBuilder;
pub use config::Config;
pub use error::Error;
pub use error::Result;
pub use server::WebServer;
pub use tokio;
Modules§
- builder
- Web 服务构建器模块
- config
- 配置管理模块
- error
- 错误处理模块
- middleware
- 中间件管理模块
- server
- Web 服务器模块
Structs§
- Cors
Layer - Layer that applies the
Cors
middleware which adds headers for CORS. - Html
- An HTML response.
- Json
- JSON Extractor / Response.
- Method
- The Request Method (VERB)
- Path
- Extractor that will get captures from the URL and parse them using
serde
. - Query
- Extractor that deserializes query strings into some type.
- Router
- The router type for composing handlers and services.
- State
- Extractor for state.
- Status
Code - An HTTP status code (
status-code
in RFC 9110 et al.).
Traits§
- Deserialize
- A data structure that can be deserialized from any data format supported by Serde.
- Into
Response - Trait for generating responses.
- Serialize
- A data structure that can be serialized into any data format supported by Serde.
Functions§
- delete
- Route
DELETE
requests to the given handler. - get
- Route
GET
requests to the given handler. - patch
- Route
PATCH
requests to the given handler. - post
- Route
POST
requests to the given handler. - put
- Route
PUT
requests to the given handler.