26 个版本 (17 个重大变更)
0.17.0-beta.1 | 2021 年 12 月 6 日 |
---|---|
0.16.0 | 2021 年 1 月 29 日 |
0.15.1 | 2021 年 1 月 28 日 |
0.15.0 | 2020 年 11 月 13 日 |
0.0.0 | 2018 年 8 月 10 日 |
#950 in HTTP 服务器
45,581 个月下载量
在 少于 149 个 包中使用
185KB
3K SLoC
Tide
服务 Web
Tide 是一个轻量级且实用的 Rust Web 应用程序框架,旨在快速开发。它包含了一组强大的功能,使构建异步 Web 应用程序和 API 变得更加容易和有趣。
入门
为了在 Rust 中构建 Web 应用程序,你需要一个 HTTP 服务器和一个异步运行时。运行 cargo init
后,将以下行添加到您的 Cargo.toml
文件中
# Example, use the version numbers you need
tide = "0.16.0"
async-std = { version = "1.8.0", features = ["attributes"] }
serde = { version = "1.0", features = ["derive"] }
示例
创建一个 HTTP 服务器,接收 JSON 主体,验证它,并以确认消息响应。
use tide::Request;
use tide::prelude::*;
#[derive(Debug, Deserialize)]
struct Animal {
name: String,
legs: u8,
}
#[async_std::main]
async fn main() -> tide::Result<()> {
let mut app = tide::new();
app.at("/orders/shoes").post(order_shoes);
app.listen("127.0.0.1:8080").await?;
Ok(())
}
async fn order_shoes(mut req: Request<()>) -> tide::Result {
let Animal { name, legs } = req.body_json().await?;
Ok(format!("Hello, {}! I've put in an order for {} shoes", name, legs).into())
}
$ curl localhost:8080/orders/shoes -d '{ "name": "Chashu", "legs": 4 }'
Hello, Chashu! I've put in an order for 4 shoes
$ curl localhost:8080/orders/shoes -d '{ "name": "Mary Millipede", "legs": 750 }'
number too large to fit in target type
更多示例请参阅 示例目录。
Tide 的设计
社区资源
要添加链接到该列表,请 编辑 markdown 文件 并提交拉取请求(需要 GitHub 登录)
在此列出并不代表 tide 团队的推荐或认可。请自行承担风险。
监听器
- tide-rustls 基于 async-rustls 的 tide TLS
- tide-acme 通过 Let's Encrypt 和 ACME tls-alpn-01 挑战,实现 tide 的 HTTPS 自动证书
模板引擎
- tide-tera
- tide-handlebars
- askama(包含 tide 支持)
路由器
认证
测试
中间件
- tide-compress
- tide-sqlx - SQLx 连接池与事务
- tide-trace
- tide-tracing
- opentelemetry-tide
- driftwood http 记录中间件
- tide-compressed-sse
- tide-websockets
- tide-csrf
会话存储
- async-redis-session
- async-sqlx-session(目前支持 sqlite 和 postgres)
- async-mongodb-session
示例应用
- dot dot vote
- tide-example(sqlx + askama)
- playground-tide-mongodb
- tide-morth-example
- broker(后端作为服务)
- tide-basic-crud(sqlx + tera)
- tide-graphql-mongodb
- 使用 tide、rhai、async-graphql、surf、graphql-client、handlebars-rust、jsonwebtoken 和 mongodb 等为 graphql 服务创建干净的样板代码。
- GraphQL 服务:用户注册、使用 PBKDF2 盐和哈希密码、登录、JSON web 令牌认证、更改密码、更新个人资料、用户查询 & 更改、项目查询 & 更改。
- Web 应用程序:客户端请求、获取 & 解析 GraphQL 数据、将数据渲染到模板引擎(handlebars-rust),使用 Rhai 脚本语言定义自定义助手。
- surf
- 基于 Tide 堆栈构建的博客,由 tide-graphql-mongodb 生成。
- 使用 tide、async-graphql、jsonwebtoken、mongodb 等构建的 graphql 服务的后端。
- 使用 tide、rhai、surf、graphql_client、handlebars-rust、cookie 等构建的 Web 应用程序的前端。
- tide-server-example
贡献
想要加入我们?查看指南中的“贡献”部分 The "Contributing" section of the guide 并查看一些这些问题
行为准则
项目遵守 Contributor Covenant 行为准则。这描述了从所有贡献者期望的最小行为。
许可证
根据您的选择,许可为以下之一
- Apache License,版本 2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 https://opensource.org/licenses/MIT)
。
贡献
除非您明确声明,否则您提交给工作内容的任何贡献,根据 Apache-2.0 许可证的定义,应按照上述方式双许可,不附加任何其他条款或条件。
依赖项
~10-25MB
~364K SLoC