wai-handler-hal-0.1.1.0: Wrap WAI applications to run on AWS Lambda
Copyright(C) 2021 Bellroy Pty Ltd
LicenseBSD-3-Clause
MaintainerBellroy Tech Team <haskell@bellroy.com>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Network.Wai.Handler.Hal

Description

Lifts an Application so that it can be run using mRuntime or mRuntimeWithContext'. The glue code will look something like this:

import AWS.Lambda.Runtime (mRuntime)
import Network.Wai (Application)
import qualified Network.Wai.Handler.Hal as WaiHandler

app :: Application
app = undefined -- From Servant or wherever else

main :: IO ()
main = mRuntime $ WaiHandler.run app
Synopsis

Documentation

run :: MonadIO m => Application -> ProxyRequest NoAuthorizer -> m ProxyResponse Source #

Convert a WAI Application into a function that can be run by hal's mRuntime. This is the simplest form, and probably all that you'll need. See runWithContext if you have more complex needs.

runWithContext Source #

Arguments

:: MonadIO m 
=> Vault

Vault of values to share between the application and any middleware. You can pass in Data.Vault.Lazy.empty, or mempty if you don't want to depend on vault directly.

-> PortNumber

API Gateway doesn't tell us the port it's listening on, so you have to tell it yourself. This is almost always going to be 443 (HTTPS).

-> (Key LambdaContext -> Key (ProxyRequest NoAuthorizer) -> Application)

We pass two Vault keys to the callback that provides the Application. This allows the application to look into the Vault part of each request and read hal data structures, if necessary:

  • The Key LambdaContext provides information about the Lambda invocation, function, and execution environment; and
  • The Key (ProxyRequest NoAuthorizer) provides the unmodified API Gateway representation of the HTTP request.
-> LambdaContext 
-> ProxyRequest NoAuthorizer

We force NoAuthorizer because it's a type alias for Value (i.e., should always parse), and it avoids an "ambiguous type variable" error at the use site.

-> m ProxyResponse 

Convert a WAI Application into a function that can be run by hal's mRuntimeWithContext'. This function exposes all the configurable knobs.

toWaiRequest :: Vault -> PortNumber -> ProxyRequest a -> IO Request Source #

Convert the request sent to a Lambda serving an API Gateway proxy integration into a WAI request.

Note: We aren't told the HTTP version the client is using, so we assume HTTP 1.1.