Safe Haskell | None |
---|
Handlers for endpoints in a Resource
.
- mkHandler :: Monad m => Modifier h p i o e -> (Env h p i -> ErrorT (Reason e) m o) -> Handler m
- mkInputHandler :: Monad m => Modifier () () i o e -> (i -> ErrorT (Reason e) m o) -> Handler m
- mkConstHandler :: Monad m => Modifier () () () o e -> ErrorT (Reason e) m o -> Handler m
- mkIdHandler :: MonadReader id m => Modifier h p i o e -> (i -> id -> ErrorT (Reason e) m o) -> Handler m
- mkListing :: Monad m => Modifier h p () o e -> (Range -> ErrorT (Reason e) m [o]) -> ListHandler m
- mkOrderedListing :: Monad m => Modifier h p () o e -> ((Range, Maybe String, Maybe String) -> ErrorT (Reason e) m [o]) -> ListHandler m
- data Range = Range {}
- range :: Param Range
- orderedRange :: Param (Range, Maybe String, Maybe String)
- data Env h p i = Env {}
- data GenHandler m f where
- GenHandler :: { } -> GenHandler m f
- mkGenHandler :: Monad m => Modifier h p i o e -> (Env h p i -> ErrorT (Reason e) m (Apply f o)) -> GenHandler m f
- type family Apply f a :: *
- type Handler m = GenHandler m Identity
- type ListHandler m = GenHandler m []
- secureHandler :: Handler m -> Handler m
Single handlers.
mkHandler :: Monad m => Modifier h p i o e -> (Env h p i -> ErrorT (Reason e) m o) -> Handler mSource
Create a handler for a single resource. Takes the entire environmend as input.
mkInputHandler :: Monad m => Modifier () () i o e -> (i -> ErrorT (Reason e) m o) -> Handler mSource
Create a handler for a single resource. Takes only the body information as input.
mkConstHandler :: Monad m => Modifier () () () o e -> ErrorT (Reason e) m o -> Handler mSource
Create a handler for a single resource. Doesn't take any input.
mkIdHandler :: MonadReader id m => Modifier h p i o e -> (i -> id -> ErrorT (Reason e) m o) -> Handler mSource
Create a handler for a single resource. Take body information and
the resource identifier as input. The monad m
should be a
Reader
-like type containing the idenfier.
Listings.
mkListing :: Monad m => Modifier h p () o e -> (Range -> ErrorT (Reason e) m [o]) -> ListHandler mSource
mkOrderedListing :: Monad m => Modifier h p () o e -> ((Range, Maybe String, Maybe String) -> ErrorT (Reason e) m [o]) -> ListHandler mSource
Parameter parsers for listings.
data Range
Data type for representing the requested range in list handlers.
Dictionary for taking Range
parameters. Allows two query
parameters, offset
and count
. If not passed, the defaults are 0
and 100. The maximum range that can be passed is 1000.
orderedRange :: Param (Range, Maybe String, Maybe String)Source
Dictionary for taking ordering information. In addition to the
parameters accepted by range
, this accepts order
and
direction
.
Generic handlers and core data types.
data GenHandler m f whereSource
A handler for some endpoint. The input and output types are
specified by the dictionary
, which can be created using the
combinators from Rest.Dictionary.Combinators. The inputs
(headers, parameters and body) are passed as an Env
to the
handler
. This handler runs in monad m
, combined with the
ability to throw errors. The result is either the output value, or
a list of them for list handlers.
If the secure
flag is set, this suggests to clients that the
resource should only be served over https. It has no effect when
running the API.
GenHandler :: Dict h p i o e -> (Env h p i -> ErrorT (Reason e) m (Apply f o)) -> Bool -> GenHandler m f | |
mkGenHandler :: Monad m => Modifier h p i o e -> (Env h p i -> ErrorT (Reason e) m (Apply f o)) -> GenHandler m fSource
Construct a GenHandler
using a Modifier
instead of a Dict
.
The secure
flag will be False
.
type Handler m = GenHandler m IdentitySource
A Handler
returning a single item.
type ListHandler m = GenHandler m []Source
A Handler
returning a list of items.
Convenience functions.
secureHandler :: Handler m -> Handler mSource
Set secure
to True
.