json-rpc-0.6.0.0: Fully-featured JSON-RPC 2.0 library

Safe HaskellNone
LanguageHaskell2010

Network.JsonRpc

Contents

Synopsis

Introduction

This JSON-RPC library is fully-compatible with JSON-RPC 2.0 and 1.0. It provides an interface that combines a JSON-RPC client and server. It can set and keep track of request ids to parse responses. There is support for sending and receiving notifications. You may use any underlying transport. Basic TCP client and server provided.

A JSON-RPC application using this interface is considered to be peer-to-peer, as it can send and receive all types of JSON-RPC message independent of whether it originated the connection.

Establish JSON-RPC context

runJsonRpcT Source

Arguments

:: (MonadLoggerIO m, MonadBaseControl IO m) 
=> Ver

JSON-RPC version

-> Bool

Ignore incoming requests or notifications

-> Sink Message m ()

Sink to send messages

-> Source m (Either Response Message)

Incoming messages or error responses to be returned to sender

-> JsonRpcT m a

JSON-RPC action

-> m a

Output of action

Create JSON-RPC session around conduits from transport layer. When context exits session disappears.

Conduits for encoding/decoding

Communicate with remote party

receiveRequest :: MonadLoggerIO m => JsonRpcT m (Maybe Request) Source

Receive requests from remote endpoint. Returns Nothing if incoming channel is closed or has never been opened.

sendRequest :: (MonadLoggerIO m, ToJSON q, ToRequest q, FromResponse r) => q -> JsonRpcT m (Maybe (Either ErrorObj r)) Source

Returns Nothing if did not receive response, could not parse it, or request was a notification. Just Left contains the error object returned by server if any. Just Right means response was received just right.

Transports

Client

jsonRpcTcpClient Source

Arguments

:: (MonadLoggerIO m, MonadBaseControl IO m) 
=> Ver

JSON-RPC version

-> Bool

Ignore incoming requests or notifications

-> ClientSettings

Connection settings

-> JsonRpcT m a

JSON-RPC action

-> m a

Output of action

TCP client transport for JSON-RPC.

Server

jsonRpcTcpServer Source

Arguments

:: (MonadLoggerIO m, MonadBaseControl IO m) 
=> Ver

JSON-RPC version

-> Bool

Ignore incoming requests or notifications

-> ServerSettings

Connection settings

-> JsonRpcT m ()

Action to perform on connecting client thread

-> m a 

TCP server transport for JSON-RPC.

Internal data and functions

Requests

Parsing

class FromRequest q where Source

Methods

parseParams :: Method -> Maybe (Value -> Parser q) Source

Parser for params Value in JSON-RPC request.

Encoding

class ToRequest q where Source

Methods

requestMethod :: q -> Method Source

Method associated with request data to build a request object.

requestIsNotif :: q -> Bool Source

Is this request to be sent as a notification (no id, no response)?

Instances

buildRequest Source

Arguments

:: (ToJSON q, ToRequest q) 
=> Ver

JSON-RPC version

-> q

Request data

-> Id 
-> Request 

Responses

Parsing

class FromResponse r where Source

Methods

parseResult :: Method -> Maybe (Value -> Parser r) Source

Parser for result Value in JSON-RPC response. Method corresponds to request to which this response answers.

Encoding

type Respond q m r = q -> m (Either ErrorObj r) Source

Errors

Error messages

errorInvalid :: Value -> ErrorObj Source

Invalid request.

errorParams :: Value -> ErrorObj Source

Invalid params.

errorMethod :: Method -> ErrorObj Source

Method not found.

errorId :: Id -> ErrorObj Source

Id not recognized.

Others

data Id Source

Constructors

IdInt 

Fields

getIdInt :: !Int
 
IdTxt 

Fields

getIdTxt :: !Text
 

data Ver Source

Constructors

V1

JSON-RPC 1.0

V2

JSON-RPC 2.0