11 releases

new 0.1.10 Mar 24, 2025
0.1.9 Mar 19, 2025
0.1.8 Jan 7, 2025
0.1.6 May 10, 2022
0.1.5 Jan 21, 2022

#572 in Encoding

Download history 4/week @ 2024-12-08 1/week @ 2024-12-15 223/week @ 2025-01-05 18/week @ 2025-01-12 19/week @ 2025-02-09 16/week @ 2025-02-16 4/week @ 2025-02-23 115/week @ 2025-03-16

120 downloads per month

MIT license

17KB
118 lines

Feign-RS (Rest client of Rust)

Start to use

Examples

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),
    };
}

Features

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

Dependencies

~5–20MB
~207K SLoC