Skip to content

greaka/rest-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages