#http #client #interfacer

nightly interfacer-http

A magic HTTP client, like retrofit in Java

10 releases

0.2.2 Sep 5, 2019
0.2.1 Aug 24, 2019
0.1.8 Aug 15, 2019

#236 in #client

Download history 11/week @ 2021-02-25 4/week @ 2021-03-04 5/week @ 2021-03-11 5/week @ 2021-03-18 54/week @ 2021-03-25 15/week @ 2021-04-01 18/week @ 2021-04-08 32/week @ 2021-04-15 23/week @ 2021-04-22 18/week @ 2021-04-29 6/week @ 2021-05-06 16/week @ 2021-05-13 4/week @ 2021-05-20 6/week @ 2021-05-27 7/week @ 2021-06-03 21/week @ 2021-06-10

78 downloads per month
Used in 2 crates

MIT license

63KB
1.5K SLoC

A magic http client, like retrofit in Java

// define interface

#![feature(custom_attribute, async_await, param_attrs)]
#![allow(unused_attributes)]

use interfacer_http::derive::{FromContent, ToContent};
use interfacer_http::{content_types, http::header::COOKIE, http_interface, Response, Result};
use serde_derive::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, FromContent, ToContent, Debug)]
struct User {
    name: String,
    age: i32,
}

#[http_interface]
trait UserInterface: Clone {
    #[put("/api/user/{id}?age={age}")]
    #[expect(200, content_types::APPLICATION_JSON)]
    async fn put_user(
        &self,
        id: u64,
        age: i32,
        #[body] user: &User,
        #[header(COOKIE)] cookie: &str
    ) -> Result<Response<User>>;
}

// use it
use interfacer_http_hyper::AsyncService;

Dependencies

~5–7MB
~175K SLoC