wai-handler-hal-0.4.0.0: Wrap WAI applications to run on AWS Lambda
Copyright(C) 2021 2024 Bellroy Pty Ltd
LicenseBSD-3-Clause
MaintainerBellroy Tech Team <haskell@bellroy.com>
Stabilityexperimental
Safe HaskellSafe-Inferred
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.

runWithOptions Source #

Arguments

:: MonadIO m 
=> Options

Configuration options. defaultOptions provides sensible defaults.

-> Application 
-> ProxyRequest NoAuthorizer 
-> m ProxyResponse 

A variant of run with configurable Options. Useful if you just want to override the binaryMediaTypes setting but don't need the rest of runWithContext's features.

Since: 0.4.0.0

runWithContext Source #

Arguments

:: MonadIO m 
=> Options

Configuration options. defaultOptions provides sensible defaults.

-> (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.

data Options Source #

Options that can be used to customize the behaviour of runWithContext. defaultOptions provides sensible defaults.

Constructors

Options 

Fields

  • vault :: 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 :: 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).

  • binaryMediaTypes :: [MediaType]

    To return binary data, API Gateway requires you to configure the binaryMediaTypes setting on your API, and then base64-encode your binary responses.

    If the Content-Type header in the wai Response matches any of the media types in this field, wai-handler-hal will base64-encode its response to the API Gateway.

    If you set binaryMediaTypes in your API, you should override the default (empty) list to match.

    See: Content type conversion in API Gateway in the Amazon API Gateway Developer Guide.

defaultOptions :: Options Source #

Default options for running Applications on Lambda.

toWaiRequest :: Options -> 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.