Want to create the next coolest thing with Rust? A discord bot? A new website? The next haxor information center? This is for you.
The first thing is first. In your Cargo.toml file, add the following line
rust
[dependencies]
lol_api_rs = "0.2.0"
In your main file add:
rust
extern crate lol_api_rs;
Once everything is installed, making your first call is as easy as creating a constructor function and calling an endpoint. ```rust // Use the Riot API constructor use lolapirs::client::Riot;
// Define your Riot API Key const RIOTAPIKEY: &'static str = "RGAPI-xxxxxxxxxxx";
fn main () { // Define new riot API factory // It accepts the following arguments. // The first param is your API key // The second param is the region to run your queries against. (NA is default) // The third param is if you want to use a custom logger to log debug statements let riot = Riot::new(RIOTAPIKEY, None, None);
// For our example we'll get champion information for Champion 99 - Lux
let json = riot.get_champions_by_id(99);
// Every call will return a Result<DataType, String> The below match is a simple handler for this.
match json {
Ok(j) => println!("{:?}", j),
Err(e) => println!("There was an error: {}", e)
}
} ```
Open an issue on Github or send me an email. I would love to make this more robust/better working. Aware of rate limits, better coded, etc. This is my first rust project and I'm looking forward to learning more about the language and the community.