In your Cargo.toml:
[dependencies]
"rest-client" = "0.3"
reqwest = "0.9"
[dependencies.serde]
version = "1.0"
features = [
"derive"
]
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();
}
This project is licensed under either of
at your option.
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.