ChimeHQ / JSONRPC

Swift library for JSON-RPC
BSD 3-Clause "New" or "Revised" License
28 stars 8 forks source link
ios json-rpc jsonrpc macos swift
[![Build Status][build status badge]][build status] [![Platforms][platforms badge]][platforms] [![Documentation][documentation badge]][documentation] [![Matrix][matrix badge]][matrix]

JSONRPC

A simple Swift library for JSON-RPC

Features:

Integration

dependencies: [
    .package(url: "https://github.com/ChimeHQ/JSONRPC", from: "0.9.0")
]

Usage

The core type you'll use is JSONRPCSession. It requires you set up a DataChannel object that handles reading and writing raw data.

let channel = DataChannel(...)
let session = JSONRPCSession(channel: channel)

let params = "hello" // any Encodable
let response: Decodable = try await session.sendRequest(params, method: "my_method")

Task {
    for await (request, handler, data) in session.requestSequence {
        // inspect request, possibly re-decode with more specific type,
        // and reply using the handler
    }
}

Task {
    for await (notification, data) in session.notificationSequence {
        // inspect notification
    }
}

DataChannel

The closures on the DataChannel allow different transport mechanisms to be used. The JSONRPC package provides a few basic variants:

Contributing and Collaboration

I would love to hear from you! Issues or pull requests work great. Both a Matrix space and Discord are available for live help, but I have a strong bias towards answering in the form of documentation. You can also find me on mastodon.

I prefer collaboration, and would love to find ways to work together if you have a similar project.

I prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.

By participating in this project you agree to abide by the Contributor Code of Conduct.