Getting started
Let's do it quick!
Implementation
First of all, you need the following dependencies:
repositories {
mavenCentral()
}
dependencies {
// Brawl Stars API (jvm, js)
commonMainImplementation("com.y9vad9.brawlstars:core:$version")
// Brawlify API (jvm, js)
commonMainImplementation("com.y9vad9.brawlify:core:$version")
}
Usage
Brawl Stars API
Fetching Player Data
Define your client:
Use the library’s prebuilt API client to interact with endpoints:
val client = BrawlStarsClient(apiKey = "your-api-key", engine = CIO)Regarding
engine
parameter, please refer to the Ktor Documentation on client engines.As for
apiKey
parameter, you need to obtain it here.
Fetch player details:
// error-proof way of passing player's tag, to avoid, // for example, unnecessary API calls and validation on your side: val playerTag: PlayerTag = PlayerTag.createOr("9V8LCUC0G") { // accepts both with hashtag and without error("Invalid player tag!") } val player = client.getPlayer(playerTag) player.onSuccess { println("Player Name: ${it.name}, Trophies: ${it.trophies}") }.onFailure { println("Error fetching player: ${it.message}") }Library enforces type safety with validated value classes. For the reference, take a look Value types and Validation.
Fetching Battle Data
Retrieve battle logs:
// if you're sure about input tag, you can use unsafe-way // of institating val playerTag: PlayerTag = PlayerTag.createUnsafe("9V8LCUC0G") val battles = client.getBattleLogs(playerTag) battles.onSuccess { it.forEach { battle -> if (battle.type.isRankedGameMode) { println("This is ranked game mode!") val stage = battle.getRankedStage(playerTag) if (stage >= RankedStage.DIAMOND_ONE) print("In this match was picking stage.") } println("Battle Mode: ${battle.mode}, Result: ${battle.result}") } }.onFailure { println("Error fetching battles: ${it.message}") }
Brawlify
Initialize Client:
val brawlifyClient = BrawlifyClient(engine = CIO)Get events:
brawlifyClient.getEvents() .onSuccess { events -> println("active: ${events.active}") println("upcoming: ${events.upcoming}") }
Last modified: 04 January 2025