servant-jsonrpc-client (empty) → 1.0.0
raw patch · 4 files changed
+106/−0 lines, 4 filesdep +aesondep +basedep +servantsetup-changed
Dependencies added: aeson, base, servant, servant-client-core, servant-jsonrpc
Files
- Setup.hs +2/−0
- changelog.md +3/−0
- servant-jsonrpc-client.cabal +36/−0
- src/Servant/Client/JsonRpc.hs +65/−0
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ changelog.md view
@@ -0,0 +1,3 @@+# 1.0.0++First release
+ servant-jsonrpc-client.cabal view
@@ -0,0 +1,36 @@+cabal-version: 2.4++name: servant-jsonrpc-client+version: 1.0.0+author: Ian Shipman <ics@gambolingpangolin.com>+maintainer: Ian Shipman <ics@gambolingpangolin.com>++synopsis: Generate JSON-RPC servant clients+description:+ Use this package to generate servant client functions that interact with a+ remote server via JSON-RPC over HTTP.++homepage: https://github.com/GambolingPangolin/servant-jsonrpc+license: ISC+category: Web+build-type: Simple++extra-source-files: changelog.md++source-repository head+ type: git+ location: https://github.com/GambolingPangolin/servant-jsonrpc.git++library+ default-language: Haskell2010+ hs-source-dirs: src++ exposed-modules:+ Servant.Client.JsonRpc++ build-depends:+ aeson >= 1.3 && < 1.5+ , base >= 4.11 && < 4.13+ , servant >= 0.14 && < 0.17+ , servant-client-core >= 0.14 && < 0.17+ , servant-jsonrpc >= 1.0 && < 1.1
+ src/Servant/Client/JsonRpc.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeFamilies #-}++{-# OPTIONS_GHC -fno-warn-orphans #-}++-- |+-- Module: Servant.Client.JsonRpc+--+-- This module provides support for generating JSON-RPC clients in the Servant framework.+--+-- > type Mul = JsonRpc "mul" (Int, Int) String Int+-- > mul :: (Int, Int) -> ClientM (JsonRpcResponse String Int)+-- > mul = client $ Proxy @Mul+--+-- Note: This client implementation runs over HTTP and the semantics of HTTP+-- remove the need for the message id.+module Servant.Client.JsonRpc+ ( module Servant.JsonRpc+ ) where++import Data.Aeson (FromJSON, ToJSON)+import Data.Proxy (Proxy (..))+import GHC.TypeLits (KnownSymbol, symbolVal)+import Servant.API (NoContent)+import Servant.Client.Core (HasClient (..), RunClient)++import Servant.JsonRpc+++instance (RunClient m, KnownSymbol method, ToJSON p, FromJSON e, FromJSON r)+ => HasClient m (JsonRpc method p e r) where++ type Client m (JsonRpc method p e r)+ = p -> m (JsonRpcResponse e r)++ clientWithRoute _ _ req p =+ client req jsonRpcRequest++ where+ client = clientWithRoute (Proxy @m) endpoint+ jsonRpcRequest = Request (symbolVal $ Proxy @method) p (Just 0)++ endpoint = Proxy @(JsonRpcEndpoint (JsonRpc method p e r))++ hoistClientMonad _ _ f x p = f $ x p+++instance (RunClient m, KnownSymbol method, ToJSON p)+ => HasClient m (JsonRpcNotification method p) where++ type Client m (JsonRpcNotification method p)+ = p -> m NoContent++ clientWithRoute _ _ req p =+ client req jsonRpcRequest+ where+ client = clientWithRoute (Proxy @m) endpoint+ jsonRpcRequest = Request (symbolVal $ Proxy @method) p Nothing++ endpoint = Proxy @(JsonRpcEndpoint (JsonRpcNotification method p))++ hoistClientMonad _ _ f x p = f $ x p