1 {-# LANGUAGE OverloadedStrings #-}
3 module JsonRpc ( JsonRpcRequestV1
9 import Data.ByteString.Lazy (ByteString)
10 import Control.Applicative ((<$>), (<*>), empty)
13 data JsonRpcRequestV1 = JsonRpcRequestV1 { jrpcReqMethod1 :: ByteString
14 , jrpcReqParams1 :: [ByteString]
15 , jrpcReqId1 :: ByteString
17 instance ToJSON JsonRpcRequestV1 where
18 toJSON (JsonRpcRequestV1 method params id) =
19 object [ "method" .= method
23 data JsonRpcRequestV2 = JsonRpcRequestV2 { jrpcReqMethod2 :: ByteString
24 , jrpcReqParams2 :: [ByteString]
25 , jrpcReqId2 :: ByteString
27 instance ToJSON JsonRpcRequestV2 where
28 toJSON (JsonRpcRequestV2 jrpcReqMethod2 jrpcReqParams2 jrpcReqId2) =
29 object [ "jsonrpc" .= toJSON ("2.0" :: ByteString)
30 , "method" .= jrpcReqMethod2
31 , "params" .= jrpcReqParams2
32 , "id" .= jrpcReqId2 ]
34 data JsonRpcNotification = JsonRpcNotification { jrpcNtfMethod :: ByteString
35 , jrpcNtfParams :: [ByteString]
38 data JsonRpcError = JsonRpcError { jrpcErrCode :: Int
39 , jrpcErrMessage :: ByteString
40 , jrpcErrData :: Maybe Value
43 data JsonRpcResponse = JsonRpcResponse { jrpcRspResult :: Maybe Value
44 , jrpcRspError :: JsonRpcError
45 , jrpcRspId :: ByteString