mu-rpc-0.2.0.0: Protocol-independent declaration of services and servers.

Safe HaskellNone
LanguageHaskell2010

Mu.Server

Contents

Description

A server (represented by ServerT) is a sequence of handlers (represented by HandlersT), one for each operation in the corresponding Mu service declaration.

In general, you should declare a server as:

server :: MonadServer m => ServerT w MyService m _
server = Server (h1 :<|>: h2 :<|>: ... :<|>: H0)

where each of h1, h2, ... handles each method in MyService in the order they were declared. The _ in the type allows GHC to fill in the boring and long type you would need to write there otherwise.

Implementation note: exceptions raised in handlers produce an error to be sent as response to the client. We recommend you to catch exceptions and return custom ServerErrors instead.

Synopsis

Servers and handlers

type MonadServer m = (MonadError ServerError m, MonadIO m) Source #

Constraint for monads that can be used as servers

data ServerT (w :: Type -> Type) (s :: Service snm mnm) (m :: Type -> Type) (hs :: [Type]) where Source #

Definition of a complete server for a service.

Constructors

Server :: HandlersT w methods m hs -> ServerT w (Service sname anns methods) m hs 

data HandlersT (w :: Type -> Type) (methods :: [Method mnm]) (m :: Type -> Type) (hs :: [Type]) where Source #

HandlersT is a sequence of handlers. Note that the handlers for your service must appear in the same order as they are defined.

In general you can choose any type you want for your handlers, due to the following restrictions:

  • Haskell types must be convertible to the corresponding schema type. In other words, they must implement FromSchema if they are inputs, and ToSchema if they are outputs.
  • Normal returns are represented by returning the corresponding Haskell type.
  • Input streams turn into Conduit () t m (), where t is the Haskell type for that schema type.
  • Output streams turn into an additional argument of type Conduit t Void m (). This stream should be connected to a source to get the elements.

Constructors

H0 :: HandlersT w '[] m '[] 
(:<|>:) :: Handles w args ret m h => h -> HandlersT w ms m hs -> HandlersT w (Method name anns args ret ': ms) m (h ': hs) infixr 5 

Simple servers using only IO

type ServerErrorIO = ExceptT ServerError IO Source #

Simplest monad which satisfies MonadServer.

type ServerIO w srv = ServerT w srv ServerErrorIO Source #

Simple ServerT which uses only IO and errors.

Errors which might be raised

serverError :: MonadError ServerError m => ServerError -> m a Source #

Stop the current handler, returning an error to the client.

data ServerError Source #

Errors raised in a handler.

data ServerErrorCode Source #

Possible types of errors. Some of these are handled in a special way by different transpoprt layers.

Useful when you do not want to deal with errors

alwaysOk :: MonadIO m => IO a -> m a Source #

Wrapper for handlers which do not use errors. Remember that any exception raised in IO is propagated to the client.