#tokio #api #async #api-wrapper #api-calls #gameapi

brawlhalla

使用tokio的异步搏斗厅API包装器

5个版本

0.1.4 2020年4月20日
0.1.3 2020年4月3日
0.1.2 2020年4月3日
0.1.1 2020年4月3日
0.1.0 2020年4月3日

#49 in #api-calls

自定义许可

17KB
428

brawlhalla

搏斗厅API的Rust包装器。


lib.rs:

brawlhalla - 使用tokio的异步搏斗厅API包装器

有了这个包,您现在可以从Rust方便地调用官方搏斗厅API!到目前为止,这个包有100%的API覆盖率,但没有其他功能。

创建API连接器

要调用API,您必须首先创建一个APIConnection。为此,您应该使用连接构建器。典型的API调用将如下所示

extern crate brawlhalla;
use brawlhalla::ConnectionBuilder;
#[tokio::main]
async fn main() -> Result<(), brawlhalla::APIError> {
    let conn = ConnectionBuilder::default() // Make a builder struct
        .with_apikey("your personal API key") // Configure your API key
        .build(); // Create an APIConnection from the template

    let legends = conn.legends().await?; // Retrieves data about all legends
    println!("{}", legends[0].bio_aka());
    Ok(())
}

目前,API只能通过async/tokio调用。

依赖关系

~8–12MB
~244K SLoC