| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Mig.Core.ServerFun
Description
Low-level server representarion.
The server is a function from Request to Response.
type ServerFun m = Request -> m (Maybe Response)
To use the mig library with some server library like wai/warp we need
to provide conversion of type ServerFun to the representarion of the given library.
We can convert mig server to ServerFun with function fromServer.
The Maybe type in the result encodes missing routes.
Synopsis
- type ServerFun m = Request -> m (Maybe Response)
- sendResponse :: Functor m => m Response -> ServerFun m
- withBody :: forall media a m. (MonadIO m, FromReqBody media a) => (a -> ServerFun m) -> ServerFun m
- withRawBody :: MonadIO m => (ByteString -> ServerFun m) -> ServerFun m
- withQuery :: (Monad m, FromHttpApiData a) => Text -> (a -> ServerFun m) -> ServerFun m
- withQueryFlag :: Text -> (Bool -> ServerFun m) -> ServerFun m
- withOptional :: FromHttpApiData a => Text -> (Maybe a -> ServerFun m) -> ServerFun m
- withCapture :: (Monad m, FromHttpApiData a) => Text -> (a -> ServerFun m) -> ServerFun m
- withHeader :: (Monad m, FromHttpApiData a) => HeaderName -> (a -> ServerFun m) -> ServerFun m
- withOptionalHeader :: FromHttpApiData a => HeaderName -> (Maybe a -> ServerFun m) -> ServerFun m
- withCookie :: forall a m. FromForm a => (Maybe a -> ServerFun m) -> ServerFun m
- withPathInfo :: ([Text] -> ServerFun m) -> ServerFun m
- withFullPathInfo :: (Text -> ServerFun m) -> ServerFun m
- handleServerError :: (Exception a, MonadCatch m) => (a -> ServerFun m) -> ServerFun m -> ServerFun m
Documentation
type ServerFun m = Request -> m (Maybe Response) Source #
Low-level representation of the server.
Missing route for a given request returns Nothing.
sendResponse :: Functor m => m Response -> ServerFun m Source #
Runs response getter action and returns it for any input request
withBody :: forall media a m. (MonadIO m, FromReqBody media a) => (a -> ServerFun m) -> ServerFun m Source #
Reads request body.
withRawBody :: MonadIO m => (ByteString -> ServerFun m) -> ServerFun m Source #
Reads low-level request body as byte string
withQuery :: (Monad m, FromHttpApiData a) => Text -> (a -> ServerFun m) -> ServerFun m Source #
Reads required query parameter
withOptional :: FromHttpApiData a => Text -> (Maybe a -> ServerFun m) -> ServerFun m Source #
reads optional query parameter
withCapture :: (Monad m, FromHttpApiData a) => Text -> (a -> ServerFun m) -> ServerFun m Source #
Reads capture from the path
withHeader :: (Monad m, FromHttpApiData a) => HeaderName -> (a -> ServerFun m) -> ServerFun m Source #
reads request header
withOptionalHeader :: FromHttpApiData a => HeaderName -> (Maybe a -> ServerFun m) -> ServerFun m Source #
Reads optional request header
withPathInfo :: ([Text] -> ServerFun m) -> ServerFun m Source #
Reads full path (without qury parameters)
withFullPathInfo :: (Text -> ServerFun m) -> ServerFun m Source #
Reads full path (without qury parameters)
handleServerError :: (Exception a, MonadCatch m) => (a -> ServerFun m) -> ServerFun m -> ServerFun m Source #
Handle errors