2 个版本
0.1.1 | 2022 年 8 月 20 日 |
---|---|
0.1.0 | 2022 年 8 月 19 日 |
#29 in #http-file
24KB
542 行
httpfile-rs
如何开始?
- 在
Cargo.toml
中添加依赖
[dependencies]
httpfile = "0.1"
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }
handlebars = "4"
lazy_static="1.4"
[build-dependencies]
httpfile-build = "0.1"
- 创建 http file,例如
index.http
,内容如下
### get my ip
//@name my-ip
GET https://httpbin.org/ip
User-Agent: curl/7.47.0
- 创建 Rust 模块,例如
httpbin.rs
,内容如下
// this would include code generated for package hello from .http file
httpfile::include_http!("index");
- 将以下代码添加到 build.rs
httpfle::configure()
.httpfile("index.http")
.compile()
.unwrap();
- 在您的代码中调用 HTTP 请求
let response = httpbin::my_ip().await?;
参考
- Cargo 为构建脚本设置的环境变量: https://doc.rust-lang.net.cn/cargo/reference/environment-variables.html
- reqwest:Rust 的一个舒适、包含所有电池的 HTTP 客户端 - https://github.com/seanmonstar/reqwest
依赖
~2.9–4MB
~82K SLoC