| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Network.Colchis
Description
This module defines the client monad and the type signatures for transports and prototocols.
- type JSONClient s m r = Client (s, Value) Value (ExceptT JSONClientError m) r
- type JSONClientError = (Value, Text, Value)
- call :: (ToJSON a, FromJSON r, Monad m) => s -> a -> JSONClient s m r
- type Protocol s m e = forall r. (s, Value) -> Proxy Value Value (s, Value) Value (ExceptT e m) r
- type Transport t m = MonadIO m => forall r. Value -> Server Value Value (t m) r
- runJSONClient :: (MonadTrans t, MFunctor t, MonadIO m, Monad (t m)) => Transport t m -> Protocol s m e -> JSONClient s m r -> t m (Either e (Either JSONClientError r))
- umap :: Monad m => (b' -> a') -> b' -> Proxy a' x b' x m r
- umapM :: Monad m => (b' -> m a') -> b' -> Proxy a' x b' x m r
- hoist :: MFunctor t => forall m b n. Monad m => (forall a. m a -> n a) -> t m b -> t n b
Client
type JSONClient s m r = Client (s, Value) Value (ExceptT JSONClientError m) r Source
Emits requests consisting in Values paired with some metadata. The metadata is usually the method name.
Receives Value responses.
type JSONClientError = (Value, Text, Value) Source
(request associated with the error, error message, response that caused the error)
call :: (ToJSON a, FromJSON r, Monad m) => s -> a -> JSONClient s m r Source
Protocol
type Protocol s m e = forall r. (s, Value) -> Proxy Value Value (s, Value) Value (ExceptT e m) r Source
A bidirectional Proxy waiting for a request, ready to be composed with +>> or >+>.
Protocols format incoming requests from downstream before sending them upstream. They also extract the values from returning protocol responses and send them downstream.
Protocols isolate clients from the specific details of each protocol.
Transport
type Transport t m = MonadIO m => forall r. Value -> Server Value Value (t m) r Source
A pipes Server waiting for a request, ready to be composed with +>> or >+>.
Transports send requests over the wire and receive the responses.
Running clients
runJSONClient :: (MonadTrans t, MFunctor t, MonadIO m, Monad (t m)) => Transport t m -> Protocol s m e -> JSONClient s m r -> t m (Either e (Either JSONClientError r)) Source
Utils
These functions can be used to manipulate requests flowing upstream.
umap :: Monad m => (b' -> a') -> b' -> Proxy a' x b' x m r Source
Apply a function to all requests flowing upstream in a bidirectional pipe. Returns a function that can be composed with +>> or >+>.
umapM :: Monad m => (b' -> m a') -> b' -> Proxy a' x b' x m r Source
Apply a monadic function to all requests flowing upstream in a bidirectional pipe. Returns a function that can be composed with +>> or >+>.