A server has any restful interface (like this : finduserbyid, newuser)
```shell curl 127.1:3000/user/findbyid/1
curl -X POST 127.1:3000/user/new_user \ -H 'Content-Type: application/json' \ -d '{"id":1,"name":"Link"}'
```
```toml [dependencies] feign = "1" reqwest = { version = "0.11", features = ["json"] } serde = "1.0" serde_derive = "1.0"
tokio = { version = "1.15", features = ["macros", "rt-multi-thread"] } ```
Add a user entity add derives serdederive::Deserialize and serdederive::Serialize
```rust use serdederive::Deserialize; use serdederive::Serialize;
pub struct User { pub id: i64, pub name: String, } ```
```rust
use feign::{client, ClientResult};
pub trait UserClient {
#[get(path = "/findbyid/
Use
```rust
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
```
```rust
pub trait UserClient { }
async fn main() { let userclient: UserClient = UserClient::new(); userclient .configure_host(String::from("http://127.0.0.1:3000")) .await; } ```