2个版本
0.1.1 | 2022年8月20日 |
---|---|
0.1.0 | 2022年8月19日 |
#136 in #codegen
5KB
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文件,例如
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
依赖
~6–19MB
~288K SLoC