Content Delivery API Client
A Kotlin Multiplatform client for Storyblok's Content Delivery API built on the Ktor Client Plugin.
With automatic relation resolution and custom component deserialization.
Quick start
First, add the dependency to your project:
dependencies {
implementation("com.storyblok:content-api-client:0.2.0")
}Content copied to clipboard
Then create a client and fetch a story:
val client = StoryblokClient(
accessToken = "YOUR_ACCESS_TOKEN",
version = Draft
)
// client.story(...) returns a Flow that emits up-to two values:
// - the cached version (if available)
// - the latest version from the API (if different from the cached version)
val myStory = client.story("home").first()Content copied to clipboard
Define custom components for deserialization:
@Serializable
@SerialName("page")
class Page(
val title: String,
val body: List<Component>
) : Component()
val client = StoryblokClient(
accessToken = "YOUR_ACCESS_TOKEN",
version = Draft,
serializersModule = SerializersModule {
polymorphic(Component::class, Page::class, Page.serializer())
}
)
client.story<Page>("home")
.collect { story -> println(story.content.title) }Content copied to clipboard
Other resources
You can find the full guide to the Content Delivery API Client inside README.md.