Skip to main content

Crate nimble_http

Crate nimble_http 

Source
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)
MethodHandler
方法处理器构建器
Redirect
Router
路由处理器
StatusCode
An HTTP status code (status-code in RFC 7230 et al.).
Text
文本响应包装器

Enums§

Value
Represents any valid JSON value.

Traits§

Handler
Handler trait - 用于处理 HTTP 请求
IntoResponse
转换为 HTTP 响应的 trait

Functions§

Nimble
get
创建 GET 路由
post
创建 POST 路由
post_json
创建 POST JSON 路由