JSONRPC

0.6.0

Swift library for JSON-RPC
ChimeHQ/JSONRPC

What's New

v0.6.0

2022-11-12T13:50:21Z
  • Migrate from AnyCodable to a custom JSONValue, which now supports Sendable.

Build Status License Platforms

JSONRPC

A simple Swift library for JSON-RPC. It features strong type-safety and makes no assumptions about the underlying transport stream.

Integration

Swift Package Manager

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

Classes

ProtocolTransport

This is the core class for using the protocol. It supports sending and receiving generic messages and notifications, as well as responding to protocol-level errors.

public var requestHandler: ((AnyJSONRPCRequest, Data, @escaping (AnyJSONRPCResponse) -> Void) -> Void)?
public var notificationHandler: ((AnyJSONRPCNotification, Data, @escaping (Error?) -> Void) -> Void)?
public var errorHandler: ((Error) -> Void)?

public func sendRequest<T, U>(_ params: T, method: String, responseHandler: @escaping (ResponseResult<U>) -> Void) where T: Codable, U: Decodable
public func sendNotification<T>(_ params: T?, method: String, completionHandler: @escaping (Error?) -> Void = {_ in }) where T: Codable

StdioDataTransport

This is a concrete implemenation of the DataTransport protocol, which passes data across stdio.

MessageTransport

This gives you a way to frame/delimit messages in the wire protocol. It is optional, in case you don't need/want to use that functionality. It relies on the MessageProtocol protocol.

SeperatedHTTPHeaderMessageProtocol

A concrete MessageProtocol that uses HTTP headers. It requires at least Content-Length, and by default expects all fields to be seperated by \r\n.

Suggestions or Feedback

We'd love to hear from you! Get in touch via twitter, an issue, or a pull request.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Description

  • Swift Tools 5.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Nov 13 2022 21:21:09 GMT-0500 (GMT-05:00)