20 releases

0.5.1 Jun 4, 2023
0.5.0 Jan 1, 2023
0.4.5 Sep 14, 2022
0.4.0 Jun 5, 2022
0.1.2 Mar 21, 2021

#98 in HTTP client

Download history 40/week @ 2024-02-22 10/week @ 2024-02-29 7/week @ 2024-03-07 19/week @ 2024-03-14 52/week @ 2024-03-21 11/week @ 2024-03-28

89 downloads per month
Used in entrait

MIT license

50KB
791 lines

FeignHTTP

crates.io Documentation MIT licensed CI

FeignHTTP is a declarative HTTP client. Based on rust macros.

Features

  • Easy to use
  • Asynchronous request
  • Configurable timeout settings
  • Supports form, plain text and JSON
  • Selectable HTTP backends (reqwest or isahc)

Usage

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.

Documentation

Read the documentation for more details.

License

FeignHTTP is provided under the MIT license. See LICENSE.

Dependencies

~3–19MB
~285K SLoC