< 返回版块

fly 发表于 2021-02-18 23:11

Tags:http,client,macro

use mclient::{get, Error};
use serde::{Deserialize};

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

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

    #[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);

    Ok(())
}

Ext Link: https://crates.io/crates/mclient

评论区

写评论
w 2021-03-01 10:42

更像写java的springboot了。

Mike Tang 2021-02-19 11:54

有点意思

1 共 2 条评论, 1 页