kotlinx.rpc 0.2.1 Help

Get started

kotlinx.rpc is a multiplatform Kotlin library that provides its users with tools to perform Remote Procedure Calls (RPC) using Kotlin language constructs with as easy setup as possible. The library is transport agnostic by design, so most transfer mechanisms can be used under the hood: WebSockets, HTTP Requests, gRPC, etc.

What this library is and what it is not

It is important to understand that this library is a set of tools and APIs gathered in one place with a goal of providing a great user experience when working with RPC systems in Kotlin Multiplatform projects. kotlinx.rpc provides its own in-house new RPC protocol, but it is not a library solely focused on this protocol.

The combination of Kotlin Multiplatform technology and RPC concept opens an opportunity to provide exceptional user experience while creating client-server applications, and we will create technologies that will embrace the concept in this library. This will include our own in-house RPC protocol with the focus on KMP projects, as well as integrations with other technologies, including but not limited to gRPC.


Before adding kotlinx.rpc dependencies, you need to configure your project with Gradle.

Configure the repositories

To be able to add dependencies for kotlinx.rpc artifacts, you need to define a repository from which they will be consumed.

Add the following repository in your build.gradle.kts file:

repositories { mavenCentral() }

Add runtime dependencies

kotlinx.rpc provides you with runtime dependencies (also called artifacts). To use these dependencies, you first need to define them in your project's build.gradle.kts file:

dependencies { // example kotlinx.rpc artifacts implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-client:0.2.1") implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-server:0.2.1") }

This adds the APIs needed to work with both client and server code using kotlinx.rpc.

For a full example, see the single-module Ktor app example.

kotlin { // source sets can be any other supported, ios and jvm are chosen just for an example sourceSets { iosMain { // let's say that we have code for the client in iosMain sources set implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-client:0.2.1") } jvmMain { // let's say that we have code for the server in jvmMain sources set implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-server:0.2.1") } } }

Here we define dependencies for iosMain and jvmMain source sets, but it can be any other source set that you may want to have. Also, you may want to split your application into several modules, so that you have a server in one module and a client in another.

For a full example, see the Ktor web app example

Add plugin dependencies

kotlinx.rpc provides two Gradle plugins:

To add a plugin to your project, you need to define the following in your build.gradle.kts:

plugins { id("org.jetbrains.kotlinx.rpc.plugin") version "0.2.1" }

To learn more about versioning, see Versions.

Add serialization dependency

kotlinx.rpc requires you to add kotlinx.serialization Gradle plugin to your project.

plugins { kotlin("jvm") version "1.9.24" kotlin("plugin.serialization") version "1.9.24" }

To learn how to configure serialization in kotlinx.rpc, see serialization DSL.

Last modified: 01 July 2024