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")
}

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()

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) }

Other resources

You can find the full guide to the Content Delivery API Client inside README.md.

Packages

Link copied to clipboard
common
Link copied to clipboard
common
Link copied to clipboard
common