webgear-server-1.0.1: Composable, type-safe library to build HTTP API servers
Safe HaskellNone
LanguageHaskell2010

WebGear.Server.Handler

Description

Server implementation of WebGear handlers

Synopsis

Documentation

newtype ServerHandler m a b Source #

An arrow implementing a WebGear server.

It can be thought of equivalent to the function arrow a -> m b where m is a monad. It also supports routing and possibly failing the computation when the route does not match.

Constructors

ServerHandler 

Instances

Instances details
Monad m => ArrowError RouteMismatch (ServerHandler m) Source # 
Instance details

Defined in WebGear.Server.Handler

Monad m => Arrow (ServerHandler m) Source # 
Instance details

Defined in WebGear.Server.Handler

Methods

arr :: (b -> c) -> ServerHandler m b c #

first :: ServerHandler m b c -> ServerHandler m (b, d) (c, d) #

second :: ServerHandler m b c -> ServerHandler m (d, b) (d, c) #

(***) :: ServerHandler m b c -> ServerHandler m b' c' -> ServerHandler m (b, b') (c, c') #

(&&&) :: ServerHandler m b c -> ServerHandler m b c' -> ServerHandler m b (c, c') #

Monad m => ArrowZero (ServerHandler m) Source # 
Instance details

Defined in WebGear.Server.Handler

Methods

zeroArrow :: ServerHandler m b c #

Monad m => ArrowPlus (ServerHandler m) Source # 
Instance details

Defined in WebGear.Server.Handler

Methods

(<+>) :: ServerHandler m b c -> ServerHandler m b c -> ServerHandler m b c #

Monad m => ArrowChoice (ServerHandler m) Source # 
Instance details

Defined in WebGear.Server.Handler

Methods

left :: ServerHandler m b c -> ServerHandler m (Either b d) (Either c d) #

right :: ServerHandler m b c -> ServerHandler m (Either d b) (Either d c) #

(+++) :: ServerHandler m b c -> ServerHandler m b' c' -> ServerHandler m (Either b b') (Either c c') #

(|||) :: ServerHandler m b d -> ServerHandler m c d -> ServerHandler m (Either b c) d #

Monad m => Handler (ServerHandler m) m Source # 
Instance details

Defined in WebGear.Server.Handler

Monad m => Get (ServerHandler m) Method Request Source # 
Instance details

Defined in WebGear.Server.Trait.Method

Monad m => Get (ServerHandler m) PathEnd Request Source # 
Instance details

Defined in WebGear.Server.Trait.Path

Monad m => Get (ServerHandler m) Path Request Source # 
Instance details

Defined in WebGear.Server.Trait.Path

Monad m => Set (ServerHandler m) Status Response Source # 
Instance details

Defined in WebGear.Server.Trait.Status

Monad m => Category (ServerHandler m :: Type -> Type -> Type) Source # 
Instance details

Defined in WebGear.Server.Handler

Methods

id :: forall (a :: k). ServerHandler m a a #

(.) :: forall (b :: k) (c :: k) (a :: k). ServerHandler m b c -> ServerHandler m a b -> ServerHandler m a c #

(MonadIO m, FromJSON val) => Get (ServerHandler m) (JSONBody val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Body

Methods

getTrait :: forall (ts :: [Type]). JSONBody val -> ServerHandler m (Linked ts Request) (Either (Absence (JSONBody val) Request) (Attribute (JSONBody val) Request)) #

(MonadIO m, FromByteString val) => Get (ServerHandler m) (Body val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Body

Methods

getTrait :: forall (ts :: [Type]). Body val -> ServerHandler m (Linked ts Request) (Either (Absence (Body val) Request) (Attribute (Body val) Request)) #

(Monad m, ToJSON val) => Set (ServerHandler m) (JSONBody val) Response Source # 
Instance details

Defined in WebGear.Server.Trait.Body

Methods

setTrait :: forall (ts :: [Type]). JSONBody val -> (Linked ts Response -> Response -> Attribute (JSONBody val) Response -> Linked (JSONBody val ': ts) Response) -> ServerHandler m (Linked ts Response, Attribute (JSONBody val) Response) (Linked (JSONBody val ': ts) Response) #

(Monad m, ToByteString val) => Set (ServerHandler m) (Body val) Response Source # 
Instance details

Defined in WebGear.Server.Trait.Body

Methods

setTrait :: forall (ts :: [Type]). Body val -> (Linked ts Response -> Response -> Attribute (Body val) Response -> Linked (Body val ': ts) Response) -> ServerHandler m (Linked ts Response, Attribute (Body val) Response) (Linked (Body val ': ts) Response) #

(Monad m, FromHttpApiData val) => Get (ServerHandler m) (PathVar tag val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Path

Methods

getTrait :: forall (ts :: [Type]). PathVar tag val -> ServerHandler m (Linked ts Request) (Either (Absence (PathVar tag val) Request) (Attribute (PathVar tag val) Request)) #

(Monad m, KnownSymbol name, FromHttpApiData val) => Get (ServerHandler m) (Header 'Optional 'Lenient name val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Header

Methods

getTrait :: forall (ts :: [Type]). Header 'Optional 'Lenient name val -> ServerHandler m (Linked ts Request) (Either (Absence (Header 'Optional 'Lenient name val) Request) (Attribute (Header 'Optional 'Lenient name val) Request)) #

(Monad m, KnownSymbol name, FromHttpApiData val) => Get (ServerHandler m) (Header 'Required 'Lenient name val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Header

Methods

getTrait :: forall (ts :: [Type]). Header 'Required 'Lenient name val -> ServerHandler m (Linked ts Request) (Either (Absence (Header 'Required 'Lenient name val) Request) (Attribute (Header 'Required 'Lenient name val) Request)) #

(Monad m, KnownSymbol name, FromHttpApiData val) => Get (ServerHandler m) (Header 'Optional 'Strict name val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Header

Methods

getTrait :: forall (ts :: [Type]). Header 'Optional 'Strict name val -> ServerHandler m (Linked ts Request) (Either (Absence (Header 'Optional 'Strict name val) Request) (Attribute (Header 'Optional 'Strict name val) Request)) #

(Monad m, KnownSymbol name, FromHttpApiData val) => Get (ServerHandler m) (Header 'Required 'Strict name val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Header

Methods

getTrait :: forall (ts :: [Type]). Header 'Required 'Strict name val -> ServerHandler m (Linked ts Request) (Either (Absence (Header 'Required 'Strict name val) Request) (Attribute (Header 'Required 'Strict name val) Request)) #

(Monad m, KnownSymbol name, FromHttpApiData val) => Get (ServerHandler m) (QueryParam 'Optional 'Lenient name val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.QueryParam

Methods

getTrait :: forall (ts :: [Type]). QueryParam 'Optional 'Lenient name val -> ServerHandler m (Linked ts Request) (Either (Absence (QueryParam 'Optional 'Lenient name val) Request) (Attribute (QueryParam 'Optional 'Lenient name val) Request)) #

(Monad m, KnownSymbol name, FromHttpApiData val) => Get (ServerHandler m) (QueryParam 'Required 'Lenient name val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.QueryParam

Methods

getTrait :: forall (ts :: [Type]). QueryParam 'Required 'Lenient name val -> ServerHandler m (Linked ts Request) (Either (Absence (QueryParam 'Required 'Lenient name val) Request) (Attribute (QueryParam 'Required 'Lenient name val) Request)) #

(Monad m, KnownSymbol name, FromHttpApiData val) => Get (ServerHandler m) (QueryParam 'Optional 'Strict name val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.QueryParam

Methods

getTrait :: forall (ts :: [Type]). QueryParam 'Optional 'Strict name val -> ServerHandler m (Linked ts Request) (Either (Absence (QueryParam 'Optional 'Strict name val) Request) (Attribute (QueryParam 'Optional 'Strict name val) Request)) #

(Monad m, KnownSymbol name, FromHttpApiData val) => Get (ServerHandler m) (QueryParam 'Required 'Strict name val) Request Source # 
Instance details

Defined in WebGear.Server.Trait.QueryParam

Methods

getTrait :: forall (ts :: [Type]). QueryParam 'Required 'Strict name val -> ServerHandler m (Linked ts Request) (Either (Absence (QueryParam 'Required 'Strict name val) Request) (Attribute (QueryParam 'Required 'Strict name val) Request)) #

(Monad m, KnownSymbol name, ToByteString val) => Set (ServerHandler m) (Header 'Optional 'Strict name val) Response Source # 
Instance details

Defined in WebGear.Server.Trait.Header

Methods

setTrait :: forall (ts :: [Type]). Header 'Optional 'Strict name val -> (Linked ts Response -> Response -> Attribute (Header 'Optional 'Strict name val) Response -> Linked (Header 'Optional 'Strict name val ': ts) Response) -> ServerHandler m (Linked ts Response, Attribute (Header 'Optional 'Strict name val) Response) (Linked (Header 'Optional 'Strict name val ': ts) Response) #

(Monad m, KnownSymbol name, ToByteString val) => Set (ServerHandler m) (Header 'Required 'Strict name val) Response Source # 
Instance details

Defined in WebGear.Server.Trait.Header

Methods

setTrait :: forall (ts :: [Type]). Header 'Required 'Strict name val -> (Linked ts Response -> Response -> Attribute (Header 'Required 'Strict name val) Response -> Linked (Header 'Required 'Strict name val ': ts) Response) -> ServerHandler m (Linked ts Response, Attribute (Header 'Required 'Strict name val) Response) (Linked (Header 'Required 'Strict name val ': ts) Response) #

(Monad m, Get (ServerHandler m) (AuthorizationHeader scheme) Request) => Get (ServerHandler m) (BasicAuth' 'Optional scheme m e a) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Auth.Basic

Methods

getTrait :: forall (ts :: [Type]). BasicAuth' 'Optional scheme m e a -> ServerHandler m (Linked ts Request) (Either (Absence (BasicAuth' 'Optional scheme m e a) Request) (Attribute (BasicAuth' 'Optional scheme m e a) Request)) #

(Monad m, Get (ServerHandler m) (AuthorizationHeader scheme) Request) => Get (ServerHandler m) (BasicAuth' 'Required scheme m e a) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Auth.Basic

Methods

getTrait :: forall (ts :: [Type]). BasicAuth' 'Required scheme m e a -> ServerHandler m (Linked ts Request) (Either (Absence (BasicAuth' 'Required scheme m e a) Request) (Attribute (BasicAuth' 'Required scheme m e a) Request)) #

(MonadTime m, Get (ServerHandler m) (AuthorizationHeader scheme) Request) => Get (ServerHandler m) (JWTAuth' 'Optional scheme m e a) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Auth.JWT

Methods

getTrait :: forall (ts :: [Type]). JWTAuth' 'Optional scheme m e a -> ServerHandler m (Linked ts Request) (Either (Absence (JWTAuth' 'Optional scheme m e a) Request) (Attribute (JWTAuth' 'Optional scheme m e a) Request)) #

(MonadTime m, Get (ServerHandler m) (AuthorizationHeader scheme) Request) => Get (ServerHandler m) (JWTAuth' 'Required scheme m e a) Request Source # 
Instance details

Defined in WebGear.Server.Trait.Auth.JWT

Methods

getTrait :: forall (ts :: [Type]). JWTAuth' 'Required scheme m e a -> ServerHandler m (Linked ts Request) (Either (Absence (JWTAuth' 'Required scheme m e a) Request) (Attribute (JWTAuth' 'Required scheme m e a) Request)) #

newtype RoutePath #

Parts of the request path used by the routing machinery

Constructors

RoutePath [Text] 

Instances

Instances details
IsList RoutePath 
Instance details

Defined in WebGear.Core.Handler

Associated Types

type Item RoutePath #

Eq RoutePath 
Instance details

Defined in WebGear.Core.Handler

Show RoutePath 
Instance details

Defined in WebGear.Core.Handler

type Item RoutePath 
Instance details

Defined in WebGear.Core.Handler

runServerHandler Source #

Arguments

:: Monad m 
=> ServerHandler m a b

The handler to run

-> RoutePath

Path used for routing

-> a

Input value to the arrow

-> m (Either RouteMismatch b)

The result of the arrow

Run a ServerHandler to produce a result or a route mismatch error.

toApplication :: ServerHandler IO (Linked '[] Request) Response -> Application Source #

Convert a ServerHandler to a WAI application

transform :: (forall x. m x -> n x) -> ServerHandler m a b -> ServerHandler n a b Source #

Transform a ServerHandler running in one monad to another monad.

This is useful in cases where the server is running in a custom monad but you would like to convert it to a WAI application using toApplication.

Example usage with a ReaderT monad stack:

 toApplication (transform f server)
   where
     server :: ServerHandler (ReaderT r IO) (Linked '[] Request) Response
     server = ....

     f :: ReaderT r IO a -> IO a
     f action = runReaderT action r