2 个版本

0.0.2 2020年1月19日
0.0.1 2020年1月19日

#952 in HTTP 服务器


6 crates 中使用

MIT 协议

1.5MB
38K SLoC

Scrappy - Rust 最好的 Web 框架

Build Status codecov

目的

该库的目的是成为您的 Rust Web 框架。

优先事项是提供易用、快速、安全、经过良好测试和良好文档化的体验。

这是 Actix-Web & Actix 及所有子包的硬分叉


lib.rs:

scrappy web 是一个小型、实用且极快的 Rust Web 框架。

use scrappy::{web, App, Responder, HttpServer};

async fn index(info: web::Path<(String, u32)>) -> impl Responder {
    format!("Hello {}! id:{}", info.0, info.1)
}

#[scrappy_rt::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| App::new().service(
        web::resource("/{name}/{id}/index.html").to(index))
    )
        .bind("127.0.0.1:8080")?
        .run()
        .await
}

文档和社区资源

除了您目前正在查看的 API 文档外,还有其他一些资源可用

为了开始导航 API 文档,您可能需要查看以下页面

  • App: 这个结构体代表一个 scrappy-web 应用程序,用于配置路由和其他常用设置。

  • HttpServer: 这个结构体代表一个 HTTP 服务器实例,用于实例化和配置服务器。

  • web: 这个模块提供了应用程序注册所需的辅助函数和类型。

  • HttpRequestHttpResponse: 这些结构体代表 HTTP 请求和响应,并公开了用于检查、创建和利用它们的各种方法。

功能

  • 支持 HTTP/1.xHTTP/2.0 协议
  • 流式传输和管道
  • 长连接和慢请求处理
  • WebSockets 服务器/客户端
  • 透明的内容压缩/解压缩(br、gzip、deflate)
  • 可配置的请求路由
  • 多部分流
  • 使用 OpenSSL 或 native-tls 的 SSL 支持
  • 中间件(LoggerSessionCORSDefaultHeaders
  • 支持 scrappy actor 框架
  • 支持的 Rust 版本:1.39 或更高

包功能

  • client - 启用 HTTP 客户端(默认启用)
  • compress - 启用内容编码压缩支持(默认启用)
  • openssl - 通过 openssl crate 启用 SSL 支持,支持 http/2
  • rustls - 通过 rustls crate 启用 SSL 支持,支持 http/2
  • secure-cookies - 启用安全 Cookie 支持,包含 ring crate 作为依赖项,《scrappy-web》 预言词,为库开发者提供

此模块的目的是通过在 Scrappy 重量级模块顶部添加全局导入来减轻许多常见 Scrappy 特性的导入

use scrappy::dev::*;

HTTP 客户端

use scrappy::client::Client;

#[scrappy_rt::main]
async fn main() {
   let mut client = Client::default();

   // Create request builder and send request
   let response = client.get("https://rust-lang.net.cn")
      .header("User-Agent", "scrappy-web")
      .send().await;                      // <- Send http request

   println!("Response: {:?}", response);
}

依赖项

~29MB
~614K SLoC