Expand description
Nimble - 一个简单优雅的 Rust Web 框架
§示例
use nimble::{Router, get, post, Html, Json, Redirect};
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(|_| Html("<h1>Hello World</h1>".to_string())))
.route("/json", post(|params| Json(["张三", "李四", params.get("name").unwrap_or("王五")])));
.route("/baidu", get(|_| Redirect("https://www.baidu.com"))
app.run("127.0.0.1", 3000).await.unwrap();
}Structs§
- File
- Html
- HTML 响应包装器
- Json
- JSON 响应包装器
- Method
- The Request Method (VERB)
- Method
Handler - 方法处理器构建器
- Redirect
- Router
- 路由处理器
- Status
Code - An HTTP status code (
status-codein RFC 7230 et al.). - Text
- 文本响应包装器
Enums§
- Value
- Represents any valid JSON value.
Traits§
- Handler
- Handler trait - 用于处理 HTTP 请求
- Into
Response - 转换为 HTTP 响应的 trait