A lightweight Haskell implementation of JSON-RPC 2.0 protocol types with Aeson serialisation.
- Core message types: requests, responses, notifications, and errors
IsJSONRPCRequest/IsJSONRPCNotificationtype classes for automatic method dispatch viaDerivingVia- Standard error codes from the specification
- Spec-compliant JSON encoding (optional
params, errordatafield, etc.)
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE TypeFamilies #-}
import JSONRPC
import Data.Aeson (FromJSON, ToJSON)
import GHC.Generics (Generic)
-- Define your request type
data PingRequest = PingRequest
{ id :: RequestId
, params :: Maybe ()
}
deriving stock (Show, Eq, Generic)
deriving (ToJSON, FromJSON) via ViaJSONRPCRequest PingRequest
instance IsJSONRPCRequest PingRequest where
requestMethod _ = "ping"