An open API service indexing awesome lists of open source software.

https://github.com/niuhuan/feign-rs

A restful http client of rust. like java feign.
https://github.com/niuhuan/feign-rs

feign http-client restful rust

Last synced: 9 months ago
JSON representation

A restful http client of rust. like java feign.

Awesome Lists containing this project

README

          

![](images/icon.png)


Feign-RS (Rest client of Rust)

### [Start to use](https://github.com/niuhuan/feign-rs/tree/master/guides)

## Examples

```rust
use serde_derive::Deserialize;
use serde_derive::Serialize;
use std::collections::HashMap;
use feign::{client, ClientResult, Args};

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct User {
pub id: i64,
pub name: String,
}

#[derive(Args)]
pub struct PutUserArgs {
#[feign_path]
pub id: i64,
#[feign_query]
pub q: String,
#[feign_json]
pub data: User,
#[feign_headers]
pub headers: HashMap,
}

#[client(host = "http://127.0.0.1:3000", path = "/user")]
pub trait UserClient {

#[get(path = "/find_by_id/")]
async fn find_by_id(&self, #[path] id: i64) -> ClientResult>;

#[post(path = "/new_user")]
async fn new_user(&self, #[json] user: &User) -> ClientResult>;

#[put(path = "/put_user/")]
async fn put_user(&self, #[args] args: PutUserArgs) -> ClientResult;
}

#[tokio::main]
async fn main() {
let user_client: UserClient = UserClient::new();

match user_client.find_by_id(12).await {
Ok(option) => match option {
Some(user) => println!("user : {}", user.name),
None => println!("none"),
},
Err(err) => panic!("{}", err),
};
}
```

## Features

- Easy to use
- Asynchronous request
- Configurable agent
- Supports form, JSON
- Reconfig host
- Additional request processer
- Custom deserializer