Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dxx/feignhttp
:toolbox: Declarative HTTP client for rust
https://github.com/dxx/feignhttp
http rust
Last synced: 18 days ago
JSON representation
:toolbox: Declarative HTTP client for rust
- Host: GitHub
- URL: https://github.com/dxx/feignhttp
- Owner: dxx
- License: mit
- Created: 2021-03-07T04:41:57.000Z (almost 4 years ago)
- Default Branch: dev
- Last Pushed: 2023-06-14T13:37:00.000Z (over 1 year ago)
- Last Synced: 2024-05-16T01:03:13.685Z (8 months ago)
- Topics: http, rust
- Language: Rust
- Homepage: https://docs.rs/feignhttp
- Size: 193 KB
- Stars: 58
- Watchers: 0
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FeignHTTP
[![crates.io](https://img.shields.io/crates/v/feignhttp.svg)](https://crates.io/crates/feignhttp)
[![Documentation](https://docs.rs/feignhttp/badge.svg)](https://docs.rs/feignhttp)
[![MIT licensed](https://img.shields.io/github/license/dxx/feignhttp.svg?color=blue)](./LICENSE)
[![CI](https://github.com/dxx/feignhttp/workflows/CI/badge.svg)](https://github.com/dxx/feignhttp/actions?query=workflow%3ACI)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](https://github.com/seanmonstar/reqwest) or [isahc](https://github.com/sagebind/isahc))## Usage
FeignHTTP mark macros on asynchronous functions, you need a runtime for support async/await. You can use [async-std](https://github.com/async-rs/async-std) or [tokio](https://github.com/tokio-rs/tokio).
async-std:
```toml
[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }
```The feature `tokio1` is need when use reqwest as the HTTP backend.
tokio:
```toml
[dependencies]
tokio = { version = "1", features = ["full"] }
```Add `feignhttp` in your `Cargo.toml` and use default feature:
```toml
feignhttp = { version = "0.5" }
```Then add the following code:
```rust
use feignhttp::get;#[get("https://api.github.com")]
async fn github() -> feignhttp::Result {}#[tokio::main]
async fn main() -> Result<(), Box> {
let r = github().await?;
println!("result: {}", r);Ok(())
}
```The `get` attribute macro specifies get request, `feignhttp::Result` 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:
```toml
feignhttp = { version = "0.5", default-features = false, features = ["isahc-client"] }
```The `default-features = false` option disable default reqwest.
For more examples, click [here](./examples).
## Documentation
Read the [documentation](https://docs.rs/feignhttp) for more details.
## License
FeignHTTP is provided under the MIT license. See [LICENSE](./LICENSE).