boluo 0.1.1

简单易用的异步网络框架
Documentation

警告

该项目目前缺乏文档,不建议将该项目用于生产环境!

功能

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

快速开始

新建项目:

cargo new demo && cd demo

添加依赖:

[dependencies]

boluo = "0.1"

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/

更多示例

在这里可以找到更多的示例代码,并且你可以通过以下命令运行这些示例:

cd examples

cargo run --bin hello

支持的最低Rust版本(MSRV)

支持的最低Rust版本为1.75.0