Skip to content

Get Started

kkRPC Banner

kkrpc is a TypeScript-first RPC library for communication channels that are not always HTTP: child processes, Web Workers, iframes, Chrome extensions, Electron, Tauri, WebSocket servers, and message buses.

HTTP is supported, but the core design is transport-agnostic. If you only need an HTTP application API, tRPC may be a better fit. If you need one typed API surface across runtimes, kkrpc is the intended tool.

Terminal window
npm install kkrpc
Terminal window
deno add jsr:@kunkun/kkrpc

This example uses WebSocket, but the wrap() and expose() pattern is the same for other evented transports.

server.ts
import { expose } from "kkrpc"
import { webSocketTransport } from "kkrpc/ws"
import { WebSocketServer } from "ws"
const api = {
math: {
add(a: number, b: number) {
return a + b
}
},
async greet(name: string) {
return `Hello, ${name}`
}
}
export type API = typeof api
const wss = new WebSocketServer({ port: 3000 })
wss.on("connection", (socket) => {
expose(api, webSocketTransport(socket))
})
client.ts
import { wrap } from "kkrpc"
import { webSocketClientTransport } from "kkrpc/ws"
import type { API } from "./server"
const api = wrap<API>(webSocketClientTransport({ url: "ws://localhost:3000" }))
console.log(await api.greet("World"))
console.log(await api.math.add(1, 2))

Use RPCChannel when both sides expose APIs or when you need explicit ownership and cleanup.

import { RPCChannel } from "kkrpc"
const channel = new RPCChannel<LocalAPI, RemoteAPI>(transport, { expose: localAPI })
const remote = channel.getAPI()
await remote.ping()
channel.destroy()

HTTP is the exception: it is unary request/response and does not support callback arguments or server-initiated calls. Use WebSocket, stdio, workers, iframes, desktop IPC, or message buses for bidirectional traffic.

Use caseImport
Core proxy/channel APIkkrpc
Browser-safe explicit core entrykkrpc/browser
Deno-friendly core entrykkrpc/deno
Web Workerkkrpc/worker
Child process stdiokkrpc/stdio
HTTPkkrpc/http
WebSocketkkrpc/ws, kkrpc/ws/hono, kkrpc/ws/elysia
iframekkrpc/iframe
Chrome extensionkkrpc/chrome-extension
Electronkkrpc/electron
Taurikkrpc/tauri
Message buseskkrpc/rabbitmq, kkrpc/kafka, kkrpc/redis-streams, kkrpc/nats
Plugins and codecskkrpc/validation, kkrpc/middleware, kkrpc/superjson, kkrpc/inspector

Only install the integrations you use. For example, WebSocket servers commonly need ws, Hono integration needs hono, RabbitMQ needs amqplib, Kafka needs kafkajs, Redis Streams needs ioredis, and NATS needs @nats-io/transport-node.