wai-lambda-0.1.0.0: Haskell Webapps on AWS Lambda

Safe HaskellNone
LanguageHaskell2010

Network.Wai.Handler.Lambda

Synopsis

Documentation

run :: Application -> IO () Source #

Run an Application.

Continuously reads requests from stdin. Each line should be a a JSON document as described in decodeInput.

All requests will be timed out after 2 seconds. If any exception is thrown while processing the request this will return an HTTP 500 Internal Server Error.

If you need more control use handleRequest directly.

defaultTimeout :: Int Source #

Default request timeout. 2 seconds.

handleRequest Source #

Arguments

:: Application 
-> Int

Timeout in microseconds

-> ByteString

The request (see decodeInput)

-> IO () 

Parse and handle the request.

  • Returns 504 if no response is available after the specified timeout.
  • Returns 500 if an exception occurs while processing the request.
  • Throws an exception if the input cannot be parsed.

processRequest :: Application -> Request -> IO Response Source #

Run the Request through the Application.

This function is completely dependent on the 'Application. Any exception thrown by the Application will be rethrown here. No timeout is implemented: if the Application never provides a Response then processRequest won't return.

decodeInput :: ByteString -> Either (JSONPath, String) (FilePath, IO Request) Source #

Decode a ByteString into (1) a Wai Request and (2) a filepath where the response should be written. The argument is JSON document with two fields: * request: the API Gateway request (see parseRequest) * reqsponseFile: Where to write the API Gateway response (see toJSONResponse)

readResponse :: Response -> IO (Status, ResponseHeaders, ByteString) Source #

Read the status, headers and body of a Response.

writeFileAtomic :: FilePath -> ByteString -> IO () Source #

Atomically write the ByteString to the file.

Uses rename(2).

xif :: b -> ((b -> c) -> b -> c) -> c Source #

flip fix