Skip to content

DrZoddiak/KsonMulti

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KsonMulti - D&D 5e API Wrapper

KsonMulti is a Kotlin Multiplatform Project that targets JS/JVM.

This is a wrapper for D&D 5e SRD API

Installation

Kotlin/JS:

repositories {
    maven("https://repo.zodd.me/releases")
}

dependencies {
    implementation("me.zodd:KsonMulti-js:$version")
}

Kotlin/JVM

repositories {
    maven("https://repo.zodd.me/releases")
}

dependencies {
    implementation("me.zodd:KsonMulti-jvm:$version")
}

Getting Started

Import wrapper and assign default client.

import kson.KsonApi
import kson.client

private val api = KsonApi(client)

Use alternate route

private val api = KsonApi(client, "http://localhost:8080")

Retrieving data

import kson.models.Monsters
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers

val scope = CoroutineScope(Dispatchers.Default)

scope.launch {
    val monster = api.fetch<Monsters>("Goblin")
    
    println(
        """
            ${monster.name}
            ${monster.languages}
        """.trimIndent()
    )
}
import kson.models.Monsters
import kson.models.Spells
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers

val scope = CoroutineScope(Dispatchers.Default)

scope.launch {
    //Use Queryable for preset options that use varargs!
    //Returns a comma separated list of matched content.
    val monster = api.query<Monsters>(Queryable.Monsters.challengeRating(2.0,1.5,3.0))
    
    //Or query nothing for default return
    val spell = api.query<Spells>()
    
    println(spell)
}

Example Output

Displayed in the order presented above.

Goblin

Goblin Types

Monster Query

Spell Empty Query