https://github.com/danmacnaughtan/swift-jsonrpcclient
A simple Swift JSONRPC client.
https://github.com/danmacnaughtan/swift-jsonrpcclient
jsonrpc swift swift-jsonrpc-client
Last synced: 2 months ago
JSON representation
A simple Swift JSONRPC client.
- Host: GitHub
- URL: https://github.com/danmacnaughtan/swift-jsonrpcclient
- Owner: danmacnaughtan
- Created: 2018-04-20T11:25:54.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-20T11:26:40.000Z (about 7 years ago)
- Last Synced: 2025-01-06T01:09:33.226Z (4 months ago)
- Topics: jsonrpc, swift, swift-jsonrpc-client
- Language: Swift
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Swift JSONRPC Client
A simple Swift JSONRPC client.
## Requirements
* [SwiftyJSON 3.1.4](https://github.com/SwiftyJSON/SwiftyJSON)
## Usage
The example usage is using [SwiftHTTP
3.0.0](https://github.com/daltoniam/SwiftHTTP).```Swift
// create an instance of the client
let client = JSONRPCClient()// add a call (or calls) to some RPC method
client.query(id: 0, method: "some-method", params: ["some", "params"])// encode the parameters
guard let params = client.encode() else {
fatalError("No RPC method queried in client.")
}// using SwiftHTTP+PostAny
HTTP.postAny("https://mydomain/api/rpc", params: params) { response inif response.statusCode == 200 {
// create a SwiftyJSON object to be decoded
let json = JSON(data: response.data)// decode the JSONRPC message(s)
let results = client.decode(json) { exception: JSONRPCException in
// handle the RPC error
}// do something with the results
}
}
```