Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type RawResponse = (Status, ResponseHeaders, ByteString)
- data Settings = Settings {
- timeoutValue :: Int
- handleTimeout :: ByteString -> IO RawResponse
- handleException :: ByteString -> SomeException -> IO RawResponse
- run :: Application -> IO ()
- runSettings :: Settings -> Application -> IO ()
- setTimeoutSeconds :: Int -> Settings -> Settings
- setHandleException :: (ByteString -> SomeException -> IO RawResponse) -> Settings -> Settings
- setHandleTimeout :: (ByteString -> IO RawResponse) -> Settings -> Settings
- defaultSettings :: Settings
- defaultHandleException :: ByteString -> SomeException -> IO RawResponse
- defaultTimeoutValue :: Int
- defaultHandleTimeout :: ByteString -> IO RawResponse
- handleRequest :: Settings -> Application -> ByteString -> IO ()
- processRequest :: Application -> Request -> IO Response
- decodeInput :: ByteString -> Either (JSONPath, String) (FilePath, IO Request)
- data ApiGatewayRequestV2 = ApiGatewayRequestV2 {
- body :: !(Maybe Text)
- headers :: !(HashMap Text Text)
- rawQueryString :: !(Maybe Text)
- requestContext :: !RequestContext
- cookies :: !(Maybe [Text])
- isBase64Encoded :: !Bool
- data RequestContext = RequestContext {}
- data Http = Http {}
- parseRequest :: Object -> Parser (IO Request)
- originalRequestKey :: Key Object
- readResponse :: Response -> IO RawResponse
- toJSONResponse :: Status -> ResponseHeaders -> ByteString -> Object
- writeFileAtomic :: FilePath -> ByteString -> IO ()
- xif :: b -> ((b -> c) -> b -> c) -> c
- uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
Documentation
type RawResponse = (Status, ResponseHeaders, ByteString) Source #
The representation of the response sent back to API Gateway.
The settings for running an Application
.
See also:
* runSettings
For simplicity use the following setters with defaultSettings
:
* setTimeoutSeconds
* setHandleTimeout
* setHandleException
Settings | |
|
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.
runSettings :: Settings -> Application -> IO () Source #
setHandleException :: (ByteString -> SomeException -> IO RawResponse) -> Settings -> Settings Source #
setHandleTimeout :: (ByteString -> IO RawResponse) -> Settings -> Settings Source #
defaultTimeoutValue :: Int Source #
Default request timeout. 2 seconds.
:: Settings | |
-> Application | |
-> ByteString | The request (see |
-> 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
)
data ApiGatewayRequestV2 Source #
ApiGatewayRequestV2 | |
|
Instances
data RequestContext Source #
Instances
Instances
FromJSON Http Source # | |
ToJSON Http Source # | |
Defined in Network.Wai.Handler.Lambda | |
Generic Http Source # | |
Show Http Source # | |
NFData Http Source # | |
Defined in Network.Wai.Handler.Lambda | |
type Rep Http Source # | |
Defined in Network.Wai.Handler.Lambda type Rep Http = D1 ('MetaData "Http" "Network.Wai.Handler.Lambda" "wai-lambda-0.1.1.0-4kQWDCgzrvk3aqacUHRdqT" 'False) (C1 ('MetaCons "Http" 'PrefixI 'True) ((S1 ('MetaSel ('Just "method") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "path") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "protocol") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "sourceIp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)))) |
parseRequest :: Object -> Parser (IO Request) Source #
Parser for a Request
.
The input is an AWS API Gateway request event: https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-api-gateway-request
readResponse :: Response -> IO RawResponse Source #
Read the status, headers and body of a Response
.
toJSONResponse :: Status -> ResponseHeaders -> ByteString -> Object Source #
Make an API Gateway response from status, headers and body. https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-api-gateway-response
writeFileAtomic :: FilePath -> ByteString -> IO () Source #
Atomically write the ByteString
to the file.
Uses rename(2)
.