
Enables JSON-like RPCs with simple service declarations, supporting various connection mechanisms. Integrates annotations for service mapping, and provides a flexible environment setup for hosting services.
Define a service interface once in Kotlin common, then call it over HTTP, sockets, stdin/out, websockets, or in-process, without changing your service code. Built for Kotlin Multiplatform, curl-testable by default, and LSP-protocol-compatible out of the box.
@KsService
interface GreetingService : RpcService {
@KsMethod("/greet")
suspend fun greet(name: String): String
}
// Implement once
class GreetingServiceImpl : GreetingService {
override suspend fun greet(name: String) = "Hello, $name!"
}
// Host over HTTP
val env = ksrpcEnvironment { }
embeddedServer(Netty, 8080) {
routing { serveHttp("/api", GreetingServiceImpl(), env) }
}.start()
// Call from any platform
val service = HttpClient { }.asHttpChannelClient("http://localhost:8080/api", env)
.defaultChannel().toStub<GreetingService>()
println(service.greet("world")) // "Hello, world!"plugins {
id("com.monkopedia.ksrpc.plugin") version "0.11.1"
}
dependencies {
implementation("com.monkopedia.ksrpc:ksrpc-core:0.11.1")
// Add transport modules as needed:
// implementation("com.monkopedia.ksrpc:ksrpc-ktor-server:0.11.1")
// implementation("com.monkopedia.ksrpc:ksrpc-ktor-client:0.11.1")
}| Transport | Platforms | Module |
|---|---|---|
| HTTP | JVM, Native, JS/WASM (client) |
ksrpc-ktor-client, ksrpc-ktor-server
|
| WebSockets | JVM, Native, JS/WASM (client) |
ksrpc-ktor-websocket-client, ksrpc-ktor-websocket-server
|
| Sockets | JVM, POSIX Native | ksrpc-sockets |
| Stdin/out | JVM, POSIX Native | ksrpc-sockets |
| JSON-RPC 2.0 | JVM, POSIX Native | ksrpc-jsonrpc |
| Service Workers | JS (experimental) | ksrpc-service-worker |
@KsService and @KsMethod; the compiler plugin generates stubs and companions automatically. Guide
Connection supports hosting and calling services simultaneously over the same channel. Guide
RpcBinaryData with adapters for ktor, kotlinx-io, and okio.@KsError and KsrpcException. Guide
@KsContext. Guide
@KsIntrospectable to expose endpoint metadata and schemas at runtime. Guide
Flow<T> in method signatures for streaming results over any transport, backed by KsFlowService. Guide
@KsNotification for fire-and-forget semantics.ksrpc exists because gRPC and protobuf didn't quite fit. I wanted JSON on the wire so I could curl at services for testing, stdin/out support like LSP, and first-class Kotlin Multiplatform coverage. ksrpc fills that niche: simple service declarations, multiple transports, and broad platform support.
Full API reference and guides are hosted at monkopedia.github.io/ksrpc.
Copyright 2026 Jason Monk
Licensed under the Apache License, Version 2.0
Define a service interface once in Kotlin common, then call it over HTTP, sockets, stdin/out, websockets, or in-process, without changing your service code. Built for Kotlin Multiplatform, curl-testable by default, and LSP-protocol-compatible out of the box.
@KsService
interface GreetingService : RpcService {
@KsMethod("/greet")
suspend fun greet(name: String): String
}
// Implement once
class GreetingServiceImpl : GreetingService {
override suspend fun greet(name: String) = "Hello, $name!"
}
// Host over HTTP
val env = ksrpcEnvironment { }
embeddedServer(Netty, 8080) {
routing { serveHttp("/api", GreetingServiceImpl(), env) }
}.start()
// Call from any platform
val service = HttpClient { }.asHttpChannelClient("http://localhost:8080/api", env)
.defaultChannel().toStub<GreetingService>()
println(service.greet("world")) // "Hello, world!"plugins {
id("com.monkopedia.ksrpc.plugin") version "0.11.1"
}
dependencies {
implementation("com.monkopedia.ksrpc:ksrpc-core:0.11.1")
// Add transport modules as needed:
// implementation("com.monkopedia.ksrpc:ksrpc-ktor-server:0.11.1")
// implementation("com.monkopedia.ksrpc:ksrpc-ktor-client:0.11.1")
}| Transport | Platforms | Module |
|---|---|---|
| HTTP | JVM, Native, JS/WASM (client) |
ksrpc-ktor-client, ksrpc-ktor-server
|
| WebSockets | JVM, Native, JS/WASM (client) |
ksrpc-ktor-websocket-client, ksrpc-ktor-websocket-server
|
| Sockets | JVM, POSIX Native | ksrpc-sockets |
| Stdin/out | JVM, POSIX Native | ksrpc-sockets |
| JSON-RPC 2.0 | JVM, POSIX Native | ksrpc-jsonrpc |
| Service Workers | JS (experimental) | ksrpc-service-worker |
@KsService and @KsMethod; the compiler plugin generates stubs and companions automatically. Guide
Connection supports hosting and calling services simultaneously over the same channel. Guide
RpcBinaryData with adapters for ktor, kotlinx-io, and okio.@KsError and KsrpcException. Guide
@KsContext. Guide
@KsIntrospectable to expose endpoint metadata and schemas at runtime. Guide
Flow<T> in method signatures for streaming results over any transport, backed by KsFlowService. Guide
@KsNotification for fire-and-forget semantics.ksrpc exists because gRPC and protobuf didn't quite fit. I wanted JSON on the wire so I could curl at services for testing, stdin/out support like LSP, and first-class Kotlin Multiplatform coverage. ksrpc fills that niche: simple service declarations, multiple transports, and broad platform support.
Full API reference and guides are hosted at monkopedia.github.io/ksrpc.
Copyright 2026 Jason Monk
Licensed under the Apache License, Version 2.0