Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Network.JsonRpc.Server.Types
Contents
Description
This module provides support for writing handlers for JSON-RPC endpoints
Synopsis
- data MaybeContent a
- = SomeContent !a
- | EmptyContent
- type MaybeJsonRpcResponse = MaybeContent (JsonRpcResponse Value Value)
- type RawJsonRpcEndpoint = ReqBody '[JsonRpcContentType] (Request Value) :> Post '[JsonRpcContentType] MaybeJsonRpcResponse
- class RouteJsonRpc a where
- type RpcHandler a (m :: Type -> Type)
- jsonRpcRouter :: Monad m => Proxy a -> Proxy m -> RpcHandler a m -> Map String (Value -> m (MaybeContent (Either (JsonRpcErr Value) Value)))
- hoistRpcRouter :: Proxy a -> (forall x. m x -> n x) -> RpcHandler a m -> RpcHandler a n
- generalizeResponse :: (ToJSON e, ToJSON r) => Either (JsonRpcErr e) r -> Either (JsonRpcErr Value) Value
- onDecodeFail :: IsString e => String -> JsonRpcErr e
- serveJsonRpc :: (Monad m, RouteJsonRpc a) => Proxy a -> Proxy m -> RpcHandler a m -> Request Value -> m MaybeJsonRpcResponse
Documentation
data MaybeContent a #
The entire JSON RPC api is collapsed to a single endpoint. Therefore, we need a type that may or may not return content.
Constructors
SomeContent !a | |
EmptyContent |
Instances
ToJSON a => AllCTRender '[JsonRpcContentType] (MaybeContent a) # | |
Defined in Network.JsonRpc.Server.Types Methods handleAcceptH :: Proxy '[JsonRpcContentType] -> AcceptHeader -> MaybeContent a -> Maybe (ByteString, ByteString) |
type MaybeJsonRpcResponse = MaybeContent (JsonRpcResponse Value Value) #
type RawJsonRpcEndpoint = ReqBody '[JsonRpcContentType] (Request Value) :> Post '[JsonRpcContentType] MaybeJsonRpcResponse #
class RouteJsonRpc a where #
This internal class is how we accumulate a map of handlers for dispatch
Associated Types
type RpcHandler a (m :: Type -> Type) #
Methods
jsonRpcRouter :: Monad m => Proxy a -> Proxy m -> RpcHandler a m -> Map String (Value -> m (MaybeContent (Either (JsonRpcErr Value) Value))) #
hoistRpcRouter :: Proxy a -> (forall x. m x -> n x) -> RpcHandler a m -> RpcHandler a n #
Instances
(KnownSymbol method, FromJSON p) => RouteJsonRpc (JsonRpcNotification method p) # | |
Defined in Network.JsonRpc.Server.Types Associated Types type RpcHandler (JsonRpcNotification method p) m # Methods jsonRpcRouter :: Monad m => Proxy (JsonRpcNotification method p) -> Proxy m -> RpcHandler (JsonRpcNotification method p) m -> Map String (Value -> m (MaybeContent (Either (JsonRpcErr Value) Value))) # hoistRpcRouter :: Proxy (JsonRpcNotification method p) -> (forall x. m x -> n x) -> RpcHandler (JsonRpcNotification method p) m -> RpcHandler (JsonRpcNotification method p) n # | |
(RouteJsonRpc a, RouteJsonRpc b) => RouteJsonRpc (a :<|> b) # | |
Defined in Network.JsonRpc.Server.Types Associated Types type RpcHandler (a :<|> b) m # Methods jsonRpcRouter :: Monad m => Proxy (a :<|> b) -> Proxy m -> RpcHandler (a :<|> b) m -> Map String (Value -> m (MaybeContent (Either (JsonRpcErr Value) Value))) # hoistRpcRouter :: Proxy (a :<|> b) -> (forall x. m x -> n x) -> RpcHandler (a :<|> b) m -> RpcHandler (a :<|> b) n # | |
(KnownSymbol method, FromJSON p, ToJSON e, ToJSON r) => RouteJsonRpc (JsonRpc method p e r) # | |
Defined in Network.JsonRpc.Server.Types Associated Types type RpcHandler (JsonRpc method p e r) m # Methods jsonRpcRouter :: Monad m => Proxy (JsonRpc method p e r) -> Proxy m -> RpcHandler (JsonRpc method p e r) m -> Map String (Value -> m (MaybeContent (Either (JsonRpcErr Value) Value))) # hoistRpcRouter :: Proxy (JsonRpc method p e r) -> (forall x. m x -> n x) -> RpcHandler (JsonRpc method p e r) m -> RpcHandler (JsonRpc method p e r) n # |
generalizeResponse :: (ToJSON e, ToJSON r) => Either (JsonRpcErr e) r -> Either (JsonRpcErr Value) Value #
onDecodeFail :: IsString e => String -> JsonRpcErr e #
serveJsonRpc :: (Monad m, RouteJsonRpc a) => Proxy a -> Proxy m -> RpcHandler a m -> Request Value -> m MaybeJsonRpcResponse #
Collapse a to a single handler to handle RawJsonRpc
Orphan instances
(RouteJsonRpc api, HasContextEntry (context .++ DefaultErrorFormatters) ErrorFormatters) => HasServer (RawJsonRpc api :: Type) context # | |
Associated Types type ServerT (RawJsonRpc api) m Methods route :: Proxy (RawJsonRpc api) -> Context context -> Delayed env (Server (RawJsonRpc api)) -> Router env hoistServerWithContext :: Proxy (RawJsonRpc api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (RawJsonRpc api) m -> ServerT (RawJsonRpc api) n |