2个版本

0.1.1 2022年8月20日
0.1.0 2022年8月19日

#136 in #codegen

Apache-2.0

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?;

参考

依赖

~6–19MB
~288K SLoC