2 个版本

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

#29 in #http-file

Apache-2.0

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

参考

依赖

~2.9–4MB
~82K SLoC