deboa-macros 0.1.0-beta.2

Request macros for the deboa HTTP client
Documentation

Deboa Macros

Crates.io downloads crates.io Build Status Crates.io MSRV Documentation MIT licensed Codecov

deboa-macros is a collection of macros for deboa. It is close equivalent to apisauce for axios, where one macro does it all, from request to response. It used to be the home of bora macro, which has been moved to vamo-macros crate.

Features

  • json
  • xml
  • msgpack

Install

Either run from command line:

cargo add deboa-macros

Or add to your Cargo.toml:

deboa-macros = "0.0.8"

Usage

other macros

use deboa::errors::DeboaError;
use deboa_macros::{fetch, get, post, delete};
use deboa_extras::http::serde::json::JsonBody;
use deboa_tokio::Client;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct Post {
    pub id: u32,
    pub title: String,
    pub body: String,
}

#[tokio::main]
async fn main() -> Result<(), DeboaError> {
    let client = Client::default();

    // fetch macro
    let response: Vec<Post> = fetch!("https://jsonplaceholder.typicode.com/posts", &client, JsonBody, Vec<Post>);

    // get macro, returning posts serialized as json
    // let response: Vec<Post> = get!("https://jsonplaceholder.typicode.com/posts", &client, JsonBody, Vec<Post>);

    // get macro, returning text
    // let response: String = get!("https://rust-lang.org", &client);

    // get macro with headers
    // let response: String = get!("https://rust-lang.org", vec![("User-Agent", "deboa")], &client);

    // post macro
    // let response = post!(data, JsonBody, "https://jsonplaceholder.typicode.com/posts", &client);

    // delete macro
    // let response = delete!("https://jsonplaceholder.typicode.com/posts/1", &client);
    
    Ok(())
}

License

MIT and Apache-2.0

Author

Rogerio Pereira Araujo rogerio.araujo@gmail.com