#rest

macro rest-client_codegen

codegen for rest-client

4 releases (2 breaking)

0.3.0 Aug 12, 2019
0.2.0 Jun 20, 2019
0.1.1 Apr 23, 2019
0.1.0 Apr 22, 2019

#368 in #rest


Used in rest-client

MIT/Apache

5KB
75 lines

Rest Client

Install

In your Cargo.toml:

[dependencies]
"rest-client" = "0.3"
reqwest = "0.9"

[dependencies.serde]
version = "1.0"
features = [
    "derive"
]

Usage

extern crate reqwest;
extern crate rest_client;
use rest_client::*;
use serde::Deserialize;

#[rest("https://example.com/rest-api/{}/multiple?variables={}")]
#[rest("https://example.com/{}", vec)] // if it returns a json array
#[derive(Deserialize)]
struct Foo {
    hello: String,
}

fn main() {
    let foo: Foo = Foo::get(&["my", "arguments"]).unwrap();
    let bar: Vec<Foo> = Foo::get(&[42]).unwrap();
}
#[derive(Deserialize)]
struct ErrorHandler {
    err: String,
}

#[derive(Deserialize)]
#[serde(untagged)]
enum Wrapper<T> {
    Success(T),
    Errored(ErrorHandler),
}

#[rest("https://example.com/rest-api/{}", wrapper = Wrapper)]
#[derive(Deserialize)]
struct Foo {
    hello: String,
}

fn main() {
    let foo: Wrapper<Foo> = Foo::get(&["argument"]).unwrap();
}

License

This project is licensed under either of

at your option.

Contributing

I am happy about every contribution to this project.

Contributions in any form (issues, pull requests, etc.) to this project must adhere to Rust's Code of Conduct.

Dependencies

~2MB
~48K SLoC