Crates.io | rrw |
lib.rs | rrw |
version | 0.1.2 |
source | src |
created_at | 2022-03-10 14:52:08.146752 |
updated_at | 2022-04-14 09:20:46.4558 |
description | A crate to easily build clients for REST-APIs. |
homepage | https://gitlab.com/Schmiddiii/rrw |
repository | https://gitlab.com/Schmiddiii/rrw |
max_upload_size | |
id | 547649 |
size | 121,922 |
A crate to easily build clients for REST-APIs.
#[derive(Serialize)]
struct LocationQuery {
query: String,
}
#[derive(Deserialize, Debug, PartialEq, Eq)]
struct Location {
id: String,
name: String,
}
#[rest]
impl Bahn {
async fn location(&self, location: &LocationQuery) -> Result<Vec<Location>, reqwest::Error> {
RestRequest::<&LocationQuery, ()>::get("/locations").query(location)
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let bahn = Bahn::new(RestConfig::new("https://v5.db.transport.rest"));
let berlin = LocationQuery {
query: "Berlin".to_string(),
};
let results = bahn.location(&berlin).await?;
for location in results {
println!("{}: {}", location.id, location.name);
}
Ok(())
}