feign 0.1.0

Rest client of Rust
Documentation

<div align="center">
<p id="icon" style="text-shadow: rgb(48, 117, 165) 0px 0px 0px, rgb(50, 122, 172) 1px 1px 0px, rgb(52, 127, 179) 2px 2px 0px, rgb(54, 132, 186) 3px 3px 0px, rgb(56, 137, 193) 4px 4px 0px, rgb(58, 142, 200) 5px 5px 0px, rgb(60, 147, 207) 6px 6px 0px, rgb(62, 152, 214) 7px 7px 0px, rgb(64, 157, 221) 8px 8px 0px, rgb(66, 162, 228) 9px 9px 0px; font-size: 64px; color: rgb(255, 255, 255); height: 128px; width: 128px; line-height: 128px; border-radius: 50%; text-align: center; background-color: rgb(68, 167, 235);"> FR </p> 
</div>

<h1 align="center">
Feign-RS (Rest client of Rust)
</h1>


## How to use

### demo server

A server has two restful interface (find_user_by_id, new_user)

```shell
curl 127.1:3000/user/find_by_id/1      
# {"id":1,"name":"hello"}

curl -X POST 127.1:3000/user/new_user \
-H 'Content-Type: application/json' \
-d '{"id":1,"name":"Link"}'
# "Link"                                                                        ➜  ~ 
```

### make a client

```rust
use serde_derive::Deserialize;
use serde_derive::Serialize;

use feign::{client, ClientResult};

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

#[client(host = "http://127.0.0.1:3000", path = "/user")]
pub trait UserClient {
    #[get(path = "/find_by_id/<id>")]
    async fn find_by_id(&self, #[path] id: i64) -> ClientResult<Option<User>>;
    #[post(path = "/new_user")]
    async fn new_user(&self, #[json] user: &User) -> ClientResult<Option<String>>;
}
```

### call api

```rust
#[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),
    };

    match user_client
        .new_user(&User {
            id: 123,
            name: "name".to_owned(),
        })
        .await
    {
        Ok(option) => match option {
            Some(result) => println!("result : {}", result),
            None => println!("none"),
        },
        Err(err) => panic!("{}", err),
    };
}
```
```text
user : hello
result : name
```