Introducing Native API Clients for Swift & Kotlin
Storyblok is the first headless CMS that works for developers & marketers alike.
We’re proud to announce the release of a pair of libraries to help you bring Storyblok natively to Swift and Kotlin for the first time, supporting authentication, regions, cache invalidation, and error and rate limit handling out-of-the-box.
These new clients put Storyblok in the palm of your hand, allowing for native use of the Content Delivery API (CAPI) and the Management API (MAPI):
- URLSessionExtension (for Apple platforms)
- ktor-client-plugin (for Android and Kotlin Multiplatform)
Let’s take a look at both libraries to see what they have to offer.
Native API for Swift: URLSessionExtension
The URLSessionExtension package is (as you might guess) an extension for Swift’s URLSession class, which doesn’t just provide a direct, native way of calling the CAPI and MAPI within the iOS and greater Apple ecosystem, but also allows the use of its other built-in capabilities, such as background downloads when the app is suspended or not running.
To start using URLSessionExtension, navigate to your project settings in Xcode, then add the storyblok-swift repository URL under Project Dependencies, or run the following command in the terminal in your project directory:
swift package add-dependency https://github.com/storyblok/storyblok-swift.git --from 0.1.0 Once it’s been installed, if for example you want to use the Content Delivery API to fetch stories from a posts folder that contains the word “solar” in its name, slug, or content, you might do so like this:
let storyblok = URLSession(storyblok: .cdn(accessToken: "your_access_token"))
var request = URLRequest(storyblok: storyblok, path: "stories")
request.url!.append(queryItems: [
URLQueryItem(name: "starts_with", value: "posts"),
URLQueryItem(name: "search_term", value: "solar"),
])
let (data, response) = try await storyblok.data(for: request) Meanwhile, if you wanted to use the Management API to set up an empty draft story about the best electric vehicles this year, you might set that up like this:
let storyblok = URLSession(storyblok: .mapi(accessToken: .oauth("your_oauth_token")))
var request = URLRequest(storyblok: storyblok, path: "stories")
request.httpMethod = "POST"
request.httpBody = try JSONSerialization.data(withJSONObject: [
"story": [
"content": [
"body": [ ],
"component": "page",
],
"name": "The Best Electric Vehicles in 2026",
"slug": "best-evs-2026",
],
])
let (data, _) = try await storyblok.data(for: request)
let body = try JSONSerialization.jsonObject(with: data) as! [String: Any]
let story = body["story"] as! [String: Any]
print("Story \(story["name"]!) created") If you want to learn more about the Swift client, what it can do, and how to use it, you can take a look at the storyblok-swift repository on GitHub, along with a number of examples of ways to use it, as well as both the documentation and User Guide.
Native API for Kotlin: ktor-client-plugin
ktor-client-plugin is (just like the name suggests) a custom client plugin for the Ktor HTTP client, which allows you to share code across not just Android devices, but also iOS, desktop, and web, as well as utilize Kotlin features like coroutines to handle multiple asynchronous requests.
To add the library as a dependency to your project (using Gradle as an example), add the following line to the dependencies block of your build file:
dependencies {
// ...
implementation("com.storyblok:ktor-client-storyblok-android:0.1.0")
} Once it is added and ready, if you want (for instance) to fetch the specific story in the posts folder with the slug vacationing-in-venice, it would be a simple call to the Content Delivery API:
val client = HttpClient {
install(Storyblok(CDN)) { accessToken = "your_access_token" }
}
val response = client.get("stories/posts/vacationing-in-venice") Likewise, if you wanted to use the Management API to create a space for your local dentist’s office, you might do so like this:
val client = HttpClient {
install(Storyblok(MAPI)) {
accessToken = OAuth("your_oauth_token")
}
}
val response = client.post("spaces/") {
setBody(buildJsonObject {
putJsonObject("space") {
put("name", "Zahnmann Dentistry")
}
})
} Like with the previous client, there are a number of resources at your disposal if you want to dive a bit deeper with the Kotlin client, from the storyblok-kotlin GitHub repository (and its own example code snippets for accessing the CAPI and MAPI) to its Plugin Guide and documentation.
What’s Next
Both libraries are v0.1.0 releases, so they and the API may change and evolve based on community feedback. We encourage you to experiment with these new clients, and share any issues or feedback you have to the Swift and Kotlin library repos, or the community channel of the Storyblok Discord server.
If you’re interested in a more complete development solution, keep an eye out for updates from the Storyblok team—we currently have an Android SDK in alpha targeting a full release very soon, and an Apple SDK coming later this year.