Skip to content

dpella/jsonrpc

Repository files navigation

jsonrpc

Hackage

A lightweight Haskell implementation of JSON-RPC 2.0 protocol types with Aeson serialisation.

Features

  • Core message types: requests, responses, notifications, and errors
  • IsJSONRPCRequest / IsJSONRPCNotification type classes for automatic method dispatch via DerivingVia
  • Standard error codes from the specification
  • Spec-compliant JSON encoding (optional params, error data field, 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"

License

MPL-2.0

About

Haskell implementation of JSONRPC 2.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published