Swiftpack.co - sidepelican/CallableKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by sidepelican.
sidepelican/CallableKit 1.4.0
Typesafe rpc with Swift server
⭐️ 0
🕓 2 weeks ago
.package(url: "https://github.com/sidepelican/CallableKit.git", from: "1.4.0")


CallableKit provides typesafe rpc with Swift server

Supported clients

  • Swift (with Foundation)
  • TypeScript (with fetch)


  • Define interface protocol and share this module for server and client.
public protocol EchoServiceProtocol {
    func hello(request: EchoHelloRequest) async throws -> EchoHelloResponse

public struct EchoHelloRequest: Codable, Sendable {
    public init(name: String) {
        self.name = name
    public var name: String

public struct EchoHelloResponse: Codable, Sendable {
    public init(message: String) {
        self.message = message
    public var message: String
  • Run code generation

  • Server implements thet protocol and register to routes.

import Vapor

struct EchoService: EchoServiceProtocol {
    func hello(request: EchoHelloRequest) async throws -> EchoHelloResponse {
        return .init(message: "Hello, \(request.name)!")

let app = Application()
defer { app.shutdown() }
let echoProvider = EchoServiceProvider { _ in // EchoServiceProvider is generated type
try app.register(collection: echoProvider)
try app.run()
  • Client can call the functions through stub client. Using the same protocol.
let client: some StubClientProtocol = FoundationHTTPStubClient(
    baseURL: URL(string: "")!,
// .echo.hello is generated extension
let res = try await client.echo.hello(request: .init(name: "Swift"))
print(res.message) // Hello, Swift!
  • TypeScript client also supported!
const stub = createStubClient("");
const echoClient = bindEcho(stub);
const res = await echoClient.hello({ name: "TypeScript" });
console.log(res.message); // Hello, TypeScript!
//           ^? res: { message: string }

Swift types are coverted to TS types powered by CodableToTypeScript

Run code generation

  • Checkout this repo and simply run executable command
$ swift run codegen Sources/APIDefinition \
    --client_out Sources/Client/Gen \
    --vapor_out Sources/Server/Gen \
    --ts_out TSClient/src/Gen \

Mint is useful to checkout and run.


  • Use from package plugin (see example)

    Add plugin target in your Package.swift (or add dedicated Package.swift for independency)

    dependencies: [
        .package(url: "https://github.com/sidepelican/CallableKit", from: "1.0.0"),
    targets: [
            name: "CodegenPlugin",
            capability: .command(
                intent: .custom(verb: "codegen", description: "Generate codes from Sources/APIDefinition"),
                permissions: [.writeToPackageDirectory(reason: "Place generated code")]
            dependencies: [
                .product(name: "codegen", package: "CallableKit"),
$ swift run codegen


Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

10 weeks ago

Full Changelog: https://github.com/sidepelican/CallableKit/compare/1.2.1...1.3.0

72177c002bed5a22b028448739b5a199a53eec9b : Remove force coercing to string type of ID suffix type

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics