Crates.io | feign |
lib.rs | feign |
version | |
source | src |
created_at | 2022-01-19 14:55:07.416836+00 |
updated_at | 2025-03-24 06:10:03.995761+00 |
description | Rest client of Rust |
homepage | |
repository | https://github.com/niuhuan/feign-rs |
max_upload_size | |
id | 516781 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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>>;
}
#[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),
};
}