mig-0.2.1.0: Build lightweight and composable servers
Safe HaskellSafe-Inferred
LanguageGHC2021

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

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

withQueryFlag :: Text -> (Bool -> ServerFun m) -> ServerFun m Source #

Reads query flag

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

withCookie :: forall a m. FromForm a => (Maybe a -> ServerFun m) -> ServerFun m Source #

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