DEV Community

RockAndNull
RockAndNull

Posted on • Originally published at paleblueapps.com on

Streamline your KMP development with Pale Blue KMP Core

Streamline your KMP development with Pale Blue KMP Core

At Pale Blue, we're happy to announce our first open-source contribution: Pale Blue KMP Core. This library is designed to make Kotlin Multiplatform (KMP) development more efficient by providing ready-to-use abstractions and utilities that eliminate repetitive code when building apps for both iOS and Android (and potentially the web in the future).

Born from experience

The journey to creating Pale Blue KMP Core began with our development challenges. As we built multiple applications using Kotlin Multiplatform, we noticed ourselves creating the same abstraction layers repeatedly. From networking utilities to key-value storage solutions, these common patterns appeared in project after project.

Rather than continuing to copy-paste, we decided to extract these battle-tested utilities into a standalone library that any KMP developer can integrate into their workflow.

What's inside

The initial release of Pale Blue KMP Core focuses on two essential areas of functionality:

  1. Networking: A convenient abstraction layer built on top of Ktor that simplifies making network requests across platforms. The API manager allows for easy configuration of base URLs, logging, default headers, and response validation.
  2. Key-Value Storage: A cross-platform solution for storing and retrieving data, built on datastore and multiplatform-settings. This includes both encrypted and standard storage options.

Getting started

Adding Pale Blue KMP Core to your project is straightforward. Simply add the dependency to your build.gradle file:

dependencies {
    implementation("com.paleblueapps:kmpcore:1.0.1")
}
Enter fullscreen mode Exit fullscreen mode

From there, you can leverage the library's utilities in your shared code. For example, setting up an API manager is as simple as:

val apiManager = ApiManager(
    baseUrl = "https://api.example.com/",
    enableLogging = true,
    defaultRequestConfig = {
        header("X-ID-device", "android")
        header("X-API-Version", "1")
    },
    responseValidator = { response ->
        when (response.status.value) {
            in 200..299 -> {}
            401 -> throw Error.UnauthorizedError
            in 400..499 -> throw Error.BackendResponseError
            else -> throw Error.BackendError
        }
    },
)
Enter fullscreen mode Exit fullscreen mode

Then use it as follows:

val endpoint = Endpoint("/users", HttpMethod.Get)
val userResult: Result<User> = call(endpoint)
userResult.onSuccess { user ->
    println("User ID: ${user.id}, User Name: ${user.name}")
}.onFailure { exception ->
    println("Error: ${exception.message}")
}
Enter fullscreen mode Exit fullscreen mode

That's all you need to create a common network stack for your Android and iOS app.

Looking ahead

This is just the beginning for Pale Blue KMP Core. We plan to expand the library with additional functionality as we continue to identify common patterns across our KMP projects. Our goal is to create a comprehensive toolkit that makes cross-platform development with Kotlin Multiplatform more efficient and enjoyable.

We invite the KMP community to try out Pale Blue KMP Core, provide feedback, and even contribute to its development. Together, we can build a stronger ecosystem of tools for Kotlin Multiplatform developers.

Happy coding!

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

👋 Kindness is contagious

If you found this post helpful, please consider leaving a ❤️ or a kind comment!

Sounds good!