A library for consuming the Hyrule Compendium API in Rust
This library exposes a client that can be used to request information from the API
Start by adding the following snippet to your Cargo.toml
toml
[dependencies]
rusty_hyrule_compendium = "0.1.0"
To use this library, you'll need to instantiate the Compendium client. CompendiumClient::default();
preconfigures the underlying HTTP client and API url with sensible values.
```rust use rustyhyrulecompendium::blocking::{CompendiumApiClient, CompendiumClient}; use rustyhyrulecompendium::domain::inputs::EntryIdentifier; use rustyhyrulecompendium::Result;
fn main() -> Result<()> { // Preconfigured client using v2 of the API let client = CompendiumClient::default(); // Requests can fail for a number of reasons, see the error module for available errors let monsterentry = client.monster(EntryIdentifier::Id(123))?; // "white-maned lynel" let monstername = monsterentry.name(); // "https://botw-compendium.herokuapp.com/api/v2/entry/white-manedlynel/image" let monsterimage = monsterentry.image(); Ok(()) } ```
Each of the resources (see below for comprehensive list) have a struct representation with helper methods to the underlying data (e.g. .name()
, .image()
etc)
Here contains the raw JSON response for the example
Furthermore it's possbile to request all of the above by category but pattern matching is required to get the entries.
rust
let result = client.category(CompendiumCategory::Treasure)?;
match result {
CategoryResult::Treasure(treasure) => {
// Do something with the Vec<TreasureEntry>
}
_ => panic!("Unexpected result while search for treasure category"),
}
It's also possible to get all entries by the .all_entries()
method
E.g.
rust
let all_entries = client.all_entries()?;
// Get all creature entries that are food specific, &Vec<CreatureEntry> type
let food_creatures = all_entries.creatures().food();