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.
// takes a struct with all of the handler functions needed.
public func setHandlers(_ handlers: Handlers)
public func sendDataRequest<T>(_ params: T, method: String, responseHandler: @escaping (DataResult) -> Void) where T: Encodable
public func sendDataRequest<T>(_ params: T, method: String) async throws -> (AnyJSONRPCResponse, Data) where T: Encodable
public func sendRequest<T, U>(_ params: T, method: String, responseHandler: @escaping (ResponseResult<U>) -> Void) where T: Encodable, U: Decodable
public func sendRequest<T, U>(_ params: T, method: String) async throws -> JSONRPCResponse<U> where T: Encodable, U: Decodable
public func sendNotification<T>(_ params: T?, method: String, completionHandler: @escaping (Error?) -> Void = {_ in }) where T: Encodable
public func sendNotification<T>(_ params: T?, method: String) async throws where T: Encodable
StdioDataTransport
This is a concrete implementation 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 separated by \r\n.
Suggestions or Feedback
We’d love to hear from you! Get in touch via an issue or 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.
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
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.
StdioDataTransport
This is a concrete implementation 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 leastContent-Length
, and by default expects all fields to be separated by\r\n
.Suggestions or Feedback
We’d love to hear from you! Get in touch via an issue or 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.