8 releases (4 breaking)

0.5.0 Apr 12, 2024
0.4.0 Apr 7, 2024
0.3.2 Apr 6, 2024
0.3.1 Mar 25, 2024
0.1.1 Mar 16, 2024

#152 in HTTP server

Download history 344/week @ 2024-03-15 261/week @ 2024-03-22 27/week @ 2024-03-29 282/week @ 2024-04-05

914 downloads per month

MIT license

275KB
5.5K SLoC

boluo

简单易用的异步网络框架

可选功能

功能名 描述 默认启用
server 启用服务器和监听器
http1 添加服务器对HTTP1的支持
http2 添加服务器对HTTP2的支持
listener 启用监听器
multipart 添加对multipart/form-data格式的支持
sse 添加对服务器发送事件的支持
ws 添加对网络套接字的支持
fs 添加对静态文件的支持

快速开始

新建项目:

cargo new demo && cd demo

添加依赖:

[dependencies]
boluo = "0.5"
tokio = { version = "1", features = ["full"] }

用以下内容覆盖src/main.rs

use boluo::response::IntoResponse;
use boluo::route::Router;
use boluo::server::Server;
use tokio::net::TcpListener;

#[tokio::main]
async fn main() {
    let listener = TcpListener::bind("127.0.0.1:3000").await.unwrap();

    let app = Router::new().mount(hello);

    Server::new(listener).run(app).await.unwrap();
}

#[boluo::route("/", method = "GET")]
async fn hello() -> impl IntoResponse {
    "Hello, World!"
}

运行项目:

cargo run

访问服务:

curl http://127.0.0.1:3000/

更多示例

在这里可以找到更多的示例代码。在示例目录中,你可以通过以下命令运行示例:

cargo run --bin hello

支持的最低Rust版本(MSRV)

支持的最低Rust版本为1.75.0

Dependencies

~3–16MB
~187K SLoC