Skip to main content

Crate brawl_rs

Crate brawl_rs 

Source
Expand description

§Brawl API RS 🦀

A fast and async Rust wrapper for the Brawl Stars API.

Crates.io Documentation License

📚 Learning Project: This is my first Rust project! I’m actively learning Rust. Feel free to share feedback and contribute! 🚀

§Features

  • 📡 Complete API coverage - Support for:
    • Player profiles and statistics
    • Club information and members
    • Brawler data and abilities
    • Game modes and event rotations
    • Rankings by region
    • Battle logs and match history
  • 🎯 Easy to use - Intuitive API with sensible defaults

§Installation

Add this to your Cargo.toml:

[dependencies]
brawl-rs = "0.1.0"
tokio = { version = "1.50.0", features = ["rt", "rt-multi-thread", "macros"] }

§Quick Start

use brawl_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a client with your API token
    let client = BrawlClient::new(std::env::var("BRAWL_TOKEN")?);
    
    // Fetch player information
    let player = Player::get(&client, "20YY0G9L0").await?;
    println!("Player: {}", player.name);
    println!("Trophies: {}", player.trophies);
    println!("Level: {}", player.exp_level);
    
    Ok(())
}

§Getting Your API Token

  1. Go to Brawl Stars Developer Portal
  2. Sign in with your Supercell ID
  3. Create a new application
  4. Copy your API token

§Examples

§Fetch Player Information

use brawl_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BrawlClient::new(std::env::var("BRAWL_TOKEN")?);
    
    let player = Player::get(&client, "20YY0G9L0").await?;
    
    println!("Name: {}", player.name);
    println!("Trophies: {}", player.trophies);
    println!("Highest: {}", player.highest_trophies);
    println!("Level: {}", player.exp_level);
    println!("Brawlers: {}", player.brawlers.len());
    
    Ok(())
}

§Fetch Club Information

use brawl_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BrawlClient::new(std::env::var("BRAWL_TOKEN")?);
    
    let club = Club::get(&client, "82Y2QCCCQ").await?;
    
    println!("Club: {}", club.name);
    println!("Members: {}", club.members.len());
    println!("Trophies: {}", club.trophies);
    
    for member in &club.members {
        println!("- {} ({}): {}", member.name, member.role, member.trophies);
    }
    
    Ok(())
}

§Get All Brawlers

use brawl_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BrawlClient::new(std::env::var("BRAWL_TOKEN")?);
    
    let brawlers = Brawlers::get(&client).await?;
    
    for brawler in &brawlers.items {
        println!(
            "{}: {} star powers, {} gadgets, {} gears",
            brawler.name,
            brawler.star_powers.len(),
            brawler.gadgets.len(),
            brawler.gears.len()
        );
    }
    
    Ok(())
}

§Get Current Event Rotation

use brawl_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BrawlClient::new(std::env::var("BRAWL_TOKEN")?);
    
    let binding = Rotation::get(&client).await?;
    let rotation = binding.first().expect("No active events found");
    
    println!("Event: {}", rotation.event.mode);
    println!("Map: {}", rotation.event.map);
    println!("Active from {} to {}", rotation.start_time, rotation.end_time);
    
    Ok(())
}

§Get Rankings

use brawl_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BrawlClient::new(std::env::var("BRAWL_TOKEN")?);
    
    // Global club rankings
    let clubs = RankingsClub::get(&client, "global").await?;
    for club in &clubs.items {
        println!("#{}: {} - {} trophies", club.rank, club.name, club.trophies);
    }
    
    // Regional player rankings (e.g., USA)
    let players = RankingsPlayer::get(&client, "US").await?;
    for player in &players.items {
        println!("#{}: {} - {} trophies", player.rank, player.name, player.trophies);
    }
    
    Ok(())
}

§Get Battle Log

use brawl_rs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BrawlClient::new(std::env::var("BRAWL_TOKEN")?);
    
    let battle_log = BattleLog::get(&client, "20YY0G9L0").await?;
    
    println!("Found {} battles:", battle_log.items.len());
    
    for (i, battle) in battle_log.items.iter().enumerate().take(3) {
        println!("Battle #{}: {} - {} ({})", 
            i + 1, battle.battle.mode, battle.battle.kind, battle.battle_time);
        
        if let Some(result) = &battle.battle.result {
            println!("  Result: {}", result);
        }
        
        if let Some(star_player) = &battle.battle.star_player {
            println!("  Star Player: {} ({})", star_player.name, star_player.brawler.name);
        }
    }
    
    Ok(())
}

§Cargo features

  • player
  • club
  • events
  • brawlers
  • rankings
  • battle_log
  • all - All features
  • default - player && battle_log

§API Methods

§Player

  • Player::get(client, tag) - Get player profile information

§Club

  • Club::get(client, tag) - Get club information and members

§Brawlers

  • Brawlers::get(client) - Get all brawlers with abilities
  • BrawlerInfo::get(client, brawler_id) - Get detailed info for a specific brawler
  • BrawlerId - Enum with all brawler IDs

§Events

  • GameModes::get(client) - Get all available game modes
  • Rotation::get(client) - Get current event rotation

§Rankings

  • RankingsClub::get(client, code) - Get top clubs by region (use “global” for global rankings)
  • RankingsPlayer::get(client, code) - Get top players by region (use “global” for global rankings)

§Battle Log

  • BattleLog::get(client, tag) - Get player’s battle history and match results

§About This Project

This is my first Rust project!

If you have suggestions or spot areas where the code could be improved, please open an issue or PR! Learning feedback is highly appreciated. 📚

§License

This project is licensed under the MIT License - see the LICENSE file for details.

§Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

§Disclaimer

This is an unofficial wrapper for the Brawl Stars API. The library is not affiliated with or endorsed by Supercell.

§Support

If you have any questions or issues, please open an issue on GitHub.

Re-exports§

pub use client::BrawlClient;
pub use errors::BrawlError;

Modules§

client
HTTP client for communicating with the Brawl Stars API.
data
Static data and constants for Brawl Stars.
errors
Error types for the Brawl API client.
models
Data structures representing Brawl Stars game entities.
prelude
Re-exports of commonly used types and traits.