Description
JSON-RPC 2.0 types and type classes for Haskell.
Description
A lightweight implementation of the JSON-RPC 2.0 protocol types for Haskell with Aeson serialisation. Provides the core request, response, notification, and error types along with type classes for deriving JSON-RPC method dispatch via DerivingVia.
Implements the specification at https://www.jsonrpc.org/specification.
README.md
jsonrpc
A lightweight Haskell implementation of JSON-RPC 2.0 protocol types with Aeson serialisation.
Features
- 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.)
Quick start
{-# 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"