Swift library for JSON-RPC

Related tags

JSON JSONRPC
Overview

JSONRPC

There are already a bunch of packages out there for doing JSON-RPC in Swift. This one is just very simple and makes no assumptions about the transport stream type.

Integration

Swift Package Manager

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

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.

You might also like...
Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend
Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend

Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend. Using Argo

Library of Swiftui Views conforming to Codable, meaning we can produce JSON driven UI!

CodableView Library of Swiftui Views conforming to Codable, meaning we can produce JSON driven UI! Adding a CodableView Type Create View that conforms

🧱 A JSON decoding/encoding library that handles optimistically or strictly.
🧱 A JSON decoding/encoding library that handles optimistically or strictly.

Do you need to handle the root cause of failure in decoding JSON? We often process the value as a default value if it could not be decoded from JSON.

Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs

Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs.

Implement dynamic JSON decoding within the constraints of Swift's sound type system by working on top of Swift's Codable implementations.

DynamicCodableKit DynamicCodableKit helps you to implement dynamic JSON decoding within the constraints of Swift's sound type system by working on top

AlamofireObjectMappe - An Alamofire extension which converts JSON response data into swift objects using ObjectMapper

AlamofireObjectMapper An extension to Alamofire which automatically converts JSON response data into swift objects using ObjectMapper. Usage Given a U

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable. Elevate should no longer be used for

Freddy - A reusable framework for parsing JSON in Swift.
Freddy - A reusable framework for parsing JSON in Swift.

Why Freddy? Parsing JSON elegantly and safely can be hard, but Freddy is here to help. Freddy is a reusable framework for parsing JSON in Swift. It ha

HandyJSON is a framework written in Swift which to make converting model objects to and from JSON easy on iOS.

HandyJSON To deal with crash on iOS 14 beta4 please try version 5.0.3-beta HandyJSON is a framework written in Swift which to make converting model ob

Comments
  • Don't deliver responses out of band

    Don't deliver responses out of band

    Great library, thanks! I'd like to suggest this improvement:

    This change ensures that responses and notifications are dispatched in the order they are received with respect to each other. This is important especially for pubsub, where the response to the initial subscription request carries the subscription ID, knowledge of which is required to dispatch later subscription updates to the correct recipient.

    opened by jscheid 5
  • Implement `JSONValue` Decoder

    Implement `JSONValue` Decoder

    Here is a new feature that allows decoding a JSONValue into a Decodable.

    Its primary purpose is to allow casting an AnyJSONRPCNotification, or its payload, into a more specific type. This is useful when a type can be derived from partial notification data. For example, the notification might be a subscription update containing a subscription ID, which can be used to look up the expected payload type.

    There might be other use cases as well, for instance polymorphic responses.

    Decoding JSON first to JSONValue, then from JSONValue to the final type is somewhat inefficient compared to directly decoding to the target type. However, direct decoding can be relatively complicated depending on the use case and sacrifices flexibility. Since JSON-RPC already isn't the most efficient RPC format out there I think it's a trade-off worth making, what do you think?

    opened by jscheid 4
  • DataTransport protocol improvements

    DataTransport protocol improvements

    Hi, the current DataTransport protocol works but could be improved in some ways. (You might already have planned to do so as part of your async work?)

    1. The setReaderHandler function means that the constructor doesn't have access to the reader, which means the class variable holding the reader has to be declared optional, which means the code gets complicated by checks to see if it has been set.
    2. The write function isn't declared throws, meaning that it's forced to report errors through a side channel. It's also not compatible with async except with fire-and-forget or reporting back through a side channel.
    3. Errors during read also have to be reported through a side channel, meaning that ProtocolTransport or other objects taking a DataTransport as an input either have to be made aware of the side channel somehow, or will be oblivious to errors.

    One way of addressing the above might be to make the protocol look more like this:

    public protocol DataTransport {
        typealias ReadHandler = (Data) async throws -> Void
    
        func write(_ data: Data) async throws -> Void
        func readLoop(_ onData: @escaping ReadHandler) async throws -> Never
    }
    

    write should be self-explanatory. readLoop would keep reading until the Task is cancelled, which would replace the close function in the current protocol version. And the reader, too, can throw if there's a problem. (I think it best for the function to never return and throw on EOF, to make EOF handling more explicit and so that there is only one way for the loop to exit, but this is more or less a matter of taste.)

    The ReadHandler in the proposal is also changed to allow throw and async. I think this would let us eventually remove the dispatch queue we talked about on #2 and enable adding backpressure. Implementing that change could be left for another time, but I figured it best to change the protocol already in the interest of keeping breaking changes to a minimum.

    All of this obviously isn't compatible with Swift <5.5, I'm not sure how big of a problem that is to you. Nothing speaking against dropping compatibility from my end, but you might have other plans.

    Curious to hear what you think about all this.

    opened by jscheid 9
Releases(0.6.1)
Owner
Chime
Chime
JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift.

JSEN /ˈdʒeɪsən/ JAY-sən JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift. A JSON, as defined in the EC

Roger Oba 8 Nov 22, 2022
Swift-json - High-performance json parsing in swift

json 0.1.4 swift-json is a pure-Swift JSON parsing library designed for high-per

kelvin 43 Dec 15, 2022
JSON-Practice - JSON Practice With Swift

JSON Practice Vista creada con: Programmatic + AutoLayout Breve explicación de l

Vanesa Giselle Korbenfeld 0 Oct 29, 2021
Ss-json - High-performance json parsing in swift

json 0.1.1 swift-json is a pure-Swift JSON parsing library designed for high-per

kelvin 43 Dec 15, 2022
Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON.

JSONFeed Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON. For more information about this new feed format visit: https:/

Toto Tvalavadze 31 Nov 22, 2021
JSONNeverDie - Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die

JSONNeverDie is an auto reflection tool from JSON to Model, a user friendly JSON encoder / decoder, aims to never die. Also JSONNeverDie is a very important part of Pitaya.

John Lui 454 Oct 30, 2022
[Deprecated] A shiny JSON parsing library in Swift :sparkles: Loved by many from 2015-2021

?? Deprecation Notice ?? Gloss has been deprecated in favor of Swift's Codable framework. The existing Gloss source is not going away, however updates

Harlan Kellaway 1.6k Nov 24, 2022
Himotoki (紐解き) is a type-safe JSON decoding library written purely in Swift.

Himotoki Himotoki (紐解き) is a type-safe JSON decoding library written purely in Swift. This library is highly inspired by the popular Swift JSON parsin

IKEDA Sho 799 Dec 6, 2022
A JSON deserialization library for Swift

Mapper Mapper is a simple Swift library to convert JSON to strongly typed objects. One advantage to Mapper over some other libraries is you can have i

Lyft 1.2k Dec 29, 2022
Developed with use Swift language. As a third party library used SDWebImage. JSON parsing using URLSession with TMDB API. This app provide by the Core Data structure.

Capstone Project ?? About Developed with use Swift language. As a third party library used SDWebImage. JSON parsing using URLSession with TMDB API. Ad

Ensar Batuhan Unverdi 9 Aug 22, 2022