Ksonbin is a kotlin wrapper for jsonbin.io (A free JSON storage and JSON hosting service)
Made with ktor for light dependencies and 100% kotlin ❤️
Gradle
kotlinx-serialization gradle plugin is required for JSON serialization/de-serialization
Below is how it can be added with ksonbin, more info here
Kotlin DSL
plugins {
kotlin("plugin.serialization") version "1.3.70"
}
dependency {
implementation("in.zeromod:ksonbin:1.0")
}
Groovy DSL
plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.70'
}
dependency {
implementation "in.zeromod:ksonbin:1.0"
}
Ksonbin
is a singleton using object declarations, means statically available to use anywhere and no need to create an instance.
Initialisation that needs run only one time.
Ksonbin.init(secretKey = "YOUR_KEY_HERE")
you can grab a key from jsonbin-keys
Recommended reading this first : Jsonbin API reference
fun main() {
Ksonbin.init("YOUR_API_KEY_HERE")
val newBin: BinCreate<Chat> = Ksonbin.bin.create(Chat("Hi"))
//BinCreate(success=true, data=Chat(message=Hi), id=5efcc1f87f16b71d48a96f91, private=true)
val chat: Chat = Ksonbin.bin.read(newBin.id)
//Chat(message=Hi)
}
@Serializable
data class Chat(
val message: String
)
More samples at KsonbinSample.kt
Due an issue in kotlinx.serialization
, we need some modifications here. Hopefully will be fixed soon by commit
For adding this library to android, add the below line in build.gradle (app- level) android
block
android {
//other configs
packagingOptions {
exclude 'META-INF/*.kotlin_module'
}
}