5 releases

0.1.4 Feb 18, 2021
0.1.3 Feb 9, 2021
0.1.2 Jan 31, 2021
0.1.1 Jan 31, 2021
0.1.0 Jan 27, 2021

#48 in HTTP client

Download history 29/week @ 2021-01-25 26/week @ 2021-02-01 23/week @ 2021-02-08 69/week @ 2021-02-15 7/week @ 2021-02-22 6/week @ 2021-03-01 3/week @ 2021-03-08 10/week @ 2021-03-22 10/week @ 2021-03-29 12/week @ 2021-04-05 10/week @ 2021-04-12 9/week @ 2021-04-19

53 downloads per month

MIT license

8KB
81 lines

mclient

macro based http client for rust

examples

use mclient::{get, post, Error};
use serde::{Serialize};

#[derive(Serialize, Debug)]
struct PostData {
    name: String,
    permissions: Vec<i32>,
}

#[derive(Deserialize, Debug)]
struct IP {
    origin: String,
}


#[tokio::main]
async fn main() -> Result<(), Error> {

    #[post("https://httpbin.org/post")]
    async fn post_data(#[body]data: &PostData) -> Result<String, Error> {}

    let data = PostData {
        name: "jjj".to_string(),
        permissions: vec![100,200,300],
    };

    let res = post_data(&data).await?;

    println!("res: {:?}", res);

    #[get("https://httpbin.org/ip")]
    async fn get_ip(#[param]name: String, #[param("sex")]gender: i32, #[header]token: String) -> Result<IP, Error> {}

    let res = get_ip("mclient".to_string(), 1,"xxxx".to_string()).await?;

    println!("res: {:?}", res);

    #[get("https://httpbin.org/cookies/set/{name}/{value}")]
    async fn path_test(#[path("name")]name1: String, #[path]value: i32) -> Result<String, Error> {}

    let res = path_test("num".to_string(), 111).await?;

    println!("res: {:?}", res);


    Ok(())
}

License

This project is licensed under the MIT license.

Dependencies

~7–11MB
~246K SLoC