KsonMulti is a Kotlin Multiplatform Project that targets JS/JVM.
This is a wrapper for D&D 5e SRD API
repositories {
maven("https://repo.zodd.me/releases")
}
dependencies {
implementation("me.zodd:KsonMulti-js:$version")
}
repositories {
maven("https://repo.zodd.me/releases")
}
dependencies {
implementation("me.zodd:KsonMulti-jvm:$version")
}
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)
}
Displayed in the order presented above.