interfacer-http

Crates.iointerfacer-http
lib.rsinterfacer-http
version0.2.2
sourcesrc
created_at2019-08-08 09:19:31.118853
updated_at2019-09-05 11:40:35.994216
descriptionA magic HTTP client, like retrofit in Java
homepage
repositoryhttps://github.com/Hexilee/interfacer-http
max_upload_size
id154965
size41,914
xixi (Hexilee)

documentation

https://docs.rs/interfacer-http

README

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;
Commit count: 271

cargo fmt