Crates.io | feignhttp |
lib.rs | feignhttp |
version | 0.5.2 |
source | src |
created_at | 2021-03-16 00:49:50.317535 |
updated_at | 2024-05-25 02:22:47.265396 |
description | Declarative HTTP client for rust |
homepage | https://github.com/dxx/feignhttp |
repository | https://github.com/dxx/feignhttp |
max_upload_size | |
id | 369474 |
size | 117,158 |
FeignHTTP is a declarative HTTP client. Based on rust macros.
FeignHTTP mark macros on asynchronous functions, you need a runtime for support async/await. You can use async-std or tokio.
async-std:
[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }
The feature tokio1
is need when use reqwest as the HTTP backend.
tokio:
[dependencies]
tokio = { version = "1", features = ["full"] }
Add feignhttp
in your Cargo.toml
and use default feature:
feignhttp = { version = "0.5" }
Then add the following code:
use feignhttp::get;
#[get("https://api.github.com")]
async fn github() -> feignhttp::Result<String> {}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let r = github().await?;
println!("result: {}", r);
Ok(())
}
The get
attribute macro specifies get request, feignhttp::Result<String>
specifies the return result.
It will send get request to https://api.github.com
and receive a plain text body.
Using non-default HTTP backend:
feignhttp = { version = "0.5", default-features = false, features = ["isahc-client"] }
The default-features = false
option disable default reqwest.
For more examples, click here.
Read the documentation for more details.
FeignHTTP is provided under the MIT license. See LICENSE.