{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module Aws.Lambda.Runtime.APIGateway.Types
( ApiGatewayRequest (..),
ApiGatewayRequestContext (..),
ApiGatewayRequestContextIdentity (..),
ApiGatewayResponse (..),
ApiGatewayResponseBody (..),
ToApiGatewayResponseBody (..),
ApiGatewayDispatcherOptions (..),
mkApiGatewayResponse,
)
where
import Aws.Lambda.Utilities (toJSONText)
import Data.Aeson
( FromJSON (parseJSON),
KeyValue ((.=)),
Object,
ToJSON (toJSON),
Value (Null, Object, String),
eitherDecodeStrict,
object,
(.:),
(.:?)
)
import Data.Aeson.Types (Parser)
import qualified Data.Aeson.Key as K
import qualified Data.Aeson.Types as T
import qualified Data.CaseInsensitive as CI
import Data.HashMap.Strict (HashMap)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import GHC.Generics (Generic)
import Network.HTTP.Types (Header, ResponseHeaders)
newtype ApiGatewayDispatcherOptions = ApiGatewayDispatcherOptions
{
ApiGatewayDispatcherOptions -> Bool
propagateImpureExceptions :: Bool
}
data ApiGatewayRequest body = ApiGatewayRequest
{ forall body. ApiGatewayRequest body -> Text
apiGatewayRequestResource :: !Text,
forall body. ApiGatewayRequest body -> Text
apiGatewayRequestPath :: !Text,
forall body. ApiGatewayRequest body -> Text
apiGatewayRequestHttpMethod :: !Text,
:: !(Maybe (HashMap Text Text)),
forall body. ApiGatewayRequest body -> Maybe (HashMap Text Text)
apiGatewayRequestQueryStringParameters :: !(Maybe (HashMap Text Text)),
forall body. ApiGatewayRequest body -> Maybe (HashMap Text Text)
apiGatewayRequestPathParameters :: !(Maybe (HashMap Text Text)),
forall body. ApiGatewayRequest body -> Maybe (HashMap Text Text)
apiGatewayRequestStageVariables :: !(Maybe (HashMap Text Text)),
forall body. ApiGatewayRequest body -> Bool
apiGatewayRequestIsBase64Encoded :: !Bool,
forall body. ApiGatewayRequest body -> ApiGatewayRequestContext
apiGatewayRequestRequestContext :: !ApiGatewayRequestContext,
forall body. ApiGatewayRequest body -> Maybe body
apiGatewayRequestBody :: !(Maybe body)
}
deriving (Int -> ApiGatewayRequest body -> ShowS
forall body. Show body => Int -> ApiGatewayRequest body -> ShowS
forall body. Show body => [ApiGatewayRequest body] -> ShowS
forall body. Show body => ApiGatewayRequest body -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApiGatewayRequest body] -> ShowS
$cshowList :: forall body. Show body => [ApiGatewayRequest body] -> ShowS
show :: ApiGatewayRequest body -> String
$cshow :: forall body. Show body => ApiGatewayRequest body -> String
showsPrec :: Int -> ApiGatewayRequest body -> ShowS
$cshowsPrec :: forall body. Show body => Int -> ApiGatewayRequest body -> ShowS
Show)
instance {-# OVERLAPPING #-} FromJSON (ApiGatewayRequest Text) where
parseJSON :: Value -> Parser (ApiGatewayRequest Text)
parseJSON = forall body.
(Object -> Key -> Parser (Maybe body))
-> Value -> Parser (ApiGatewayRequest body)
parseApiGatewayRequest forall a. FromJSON a => Object -> Key -> Parser a
(.:)
instance {-# OVERLAPPING #-} FromJSON (ApiGatewayRequest String) where
parseJSON :: Value -> Parser (ApiGatewayRequest String)
parseJSON = forall body.
(Object -> Key -> Parser (Maybe body))
-> Value -> Parser (ApiGatewayRequest body)
parseApiGatewayRequest forall a. FromJSON a => Object -> Key -> Parser a
(.:)
instance FromJSON body => FromJSON (ApiGatewayRequest body) where
parseJSON :: Value -> Parser (ApiGatewayRequest body)
parseJSON = forall body.
(Object -> Key -> Parser (Maybe body))
-> Value -> Parser (ApiGatewayRequest body)
parseApiGatewayRequest forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
parseObjectFromStringField
parseObjectFromStringField :: FromJSON a => Object -> T.Key -> Parser (Maybe a)
parseObjectFromStringField :: forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
parseObjectFromStringField Object
obj Key
fieldName = do
Value
fieldContents <- Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
fieldName
case Value
fieldContents of
String Text
stringContents ->
case forall a. FromJSON a => ByteString -> Either String a
eitherDecodeStrict (Text -> ByteString
T.encodeUtf8 Text
stringContents) of
Right Maybe a
success -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
success
Left String
err -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
err
Value
Null -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing
Value
other -> forall a. String -> Value -> Parser a
T.typeMismatch String
"String or Null" Value
other
parseApiGatewayRequest :: (Object -> T.Key -> Parser (Maybe body)) -> Value -> Parser (ApiGatewayRequest body)
parseApiGatewayRequest :: forall body.
(Object -> Key -> Parser (Maybe body))
-> Value -> Parser (ApiGatewayRequest body)
parseApiGatewayRequest Object -> Key -> Parser (Maybe body)
bodyParser (Object Object
v) =
forall body.
Text
-> Text
-> Text
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text)
-> Bool
-> ApiGatewayRequestContext
-> Maybe body
-> ApiGatewayRequest body
ApiGatewayRequest
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"resource"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"path"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"httpMethod"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"headers"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"queryStringParameters"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"pathParameters"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"stageVariables"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"isBase64Encoded"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"requestContext"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe body)
`bodyParser` Key
"body"
parseApiGatewayRequest Object -> Key -> Parser (Maybe body)
_ Value
_ = forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected ApiGatewayRequest to be an object."
data ApiGatewayRequestContext = ApiGatewayRequestContext
{ ApiGatewayRequestContext -> Text
apiGatewayRequestContextResourceId :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextResourcePath :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextHttpMethod :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextExtendedRequestId :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextRequestTime :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextPath :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextAccountId :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextProtocol :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextStage :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextDomainPrefix :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextRequestId :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextDomainName :: !Text,
ApiGatewayRequestContext -> Text
apiGatewayRequestContextApiId :: !Text,
ApiGatewayRequestContext -> ApiGatewayRequestContextIdentity
apiGatewayRequestContextIdentity :: !ApiGatewayRequestContextIdentity,
ApiGatewayRequestContext -> Maybe Value
apiGatewayRequestContextAuthorizer :: !(Maybe Value)
}
deriving (Int -> ApiGatewayRequestContext -> ShowS
[ApiGatewayRequestContext] -> ShowS
ApiGatewayRequestContext -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApiGatewayRequestContext] -> ShowS
$cshowList :: [ApiGatewayRequestContext] -> ShowS
show :: ApiGatewayRequestContext -> String
$cshow :: ApiGatewayRequestContext -> String
showsPrec :: Int -> ApiGatewayRequestContext -> ShowS
$cshowsPrec :: Int -> ApiGatewayRequestContext -> ShowS
Show)
instance FromJSON ApiGatewayRequestContext where
parseJSON :: Value -> Parser ApiGatewayRequestContext
parseJSON (Object Object
v) =
Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> ApiGatewayRequestContextIdentity
-> Maybe Value
-> ApiGatewayRequestContext
ApiGatewayRequestContext
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"resourceId"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"path"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"httpMethod"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"extendedRequestId"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"requestTime"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"path"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"accountId"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"protocol"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"stage"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"domainPrefix"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"requestId"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"domainName"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"apiId"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"identity"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"authorizer"
parseJSON Value
_ = forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected ApiGatewayRequestContext to be an object."
data ApiGatewayRequestContextIdentity = ApiGatewayRequestContextIdentity
{ ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityCognitoIdentityPoolId :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityAccountId :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityCognitoIdentityId :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityCaller :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentitySourceIp :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityPrincipalOrgId :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityAccesskey :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityCognitoAuthenticationType :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Value
apiGatewayRequestContextIdentityCognitoAuthenticationProvider :: !(Maybe Value),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityUserArn :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityUserAgent :: !(Maybe Text),
ApiGatewayRequestContextIdentity -> Maybe Text
apiGatewayRequestContextIdentityUser :: !(Maybe Text)
}
deriving (Int -> ApiGatewayRequestContextIdentity -> ShowS
[ApiGatewayRequestContextIdentity] -> ShowS
ApiGatewayRequestContextIdentity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApiGatewayRequestContextIdentity] -> ShowS
$cshowList :: [ApiGatewayRequestContextIdentity] -> ShowS
show :: ApiGatewayRequestContextIdentity -> String
$cshow :: ApiGatewayRequestContextIdentity -> String
showsPrec :: Int -> ApiGatewayRequestContextIdentity -> ShowS
$cshowsPrec :: Int -> ApiGatewayRequestContextIdentity -> ShowS
Show)
instance FromJSON ApiGatewayRequestContextIdentity where
parseJSON :: Value -> Parser ApiGatewayRequestContextIdentity
parseJSON (Object Object
v) =
Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Value
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> ApiGatewayRequestContextIdentity
ApiGatewayRequestContextIdentity
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"cognitoIdentityPoolId"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"accountId"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"cognitoIdentityId"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"caller"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"sourceIp"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"principalOrgId"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"accessKey"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"cognitoAuthenticationType"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"cognitoAuthenticationProvider"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"userArn"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"userAgent"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user"
parseJSON Value
_ = forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected ApiGatewayRequestContextIdentity to be an object."
newtype ApiGatewayResponseBody
= ApiGatewayResponseBody Text
deriving newtype ([ApiGatewayResponseBody] -> Encoding
[ApiGatewayResponseBody] -> Value
ApiGatewayResponseBody -> Encoding
ApiGatewayResponseBody -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ApiGatewayResponseBody] -> Encoding
$ctoEncodingList :: [ApiGatewayResponseBody] -> Encoding
toJSONList :: [ApiGatewayResponseBody] -> Value
$ctoJSONList :: [ApiGatewayResponseBody] -> Value
toEncoding :: ApiGatewayResponseBody -> Encoding
$ctoEncoding :: ApiGatewayResponseBody -> Encoding
toJSON :: ApiGatewayResponseBody -> Value
$ctoJSON :: ApiGatewayResponseBody -> Value
ToJSON, Value -> Parser [ApiGatewayResponseBody]
Value -> Parser ApiGatewayResponseBody
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [ApiGatewayResponseBody]
$cparseJSONList :: Value -> Parser [ApiGatewayResponseBody]
parseJSON :: Value -> Parser ApiGatewayResponseBody
$cparseJSON :: Value -> Parser ApiGatewayResponseBody
FromJSON)
class ToApiGatewayResponseBody a where
toApiGatewayResponseBody :: a -> ApiGatewayResponseBody
instance {-# OVERLAPPING #-} ToApiGatewayResponseBody Text where
toApiGatewayResponseBody :: Text -> ApiGatewayResponseBody
toApiGatewayResponseBody = Text -> ApiGatewayResponseBody
ApiGatewayResponseBody
instance {-# OVERLAPPING #-} ToApiGatewayResponseBody String where
toApiGatewayResponseBody :: String -> ApiGatewayResponseBody
toApiGatewayResponseBody = Text -> ApiGatewayResponseBody
ApiGatewayResponseBody forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
instance ToJSON a => ToApiGatewayResponseBody a where
toApiGatewayResponseBody :: a -> ApiGatewayResponseBody
toApiGatewayResponseBody = Text -> ApiGatewayResponseBody
ApiGatewayResponseBody forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToJSON a => a -> Text
toJSONText
data ApiGatewayResponse body = ApiGatewayResponse
{ forall body. ApiGatewayResponse body -> Int
apiGatewayResponseStatusCode :: !Int,
:: !ResponseHeaders,
forall body. ApiGatewayResponse body -> body
apiGatewayResponseBody :: !body,
forall body. ApiGatewayResponse body -> Bool
apiGatewayResponseIsBase64Encoded :: !Bool
}
deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall body x.
Rep (ApiGatewayResponse body) x -> ApiGatewayResponse body
forall body x.
ApiGatewayResponse body -> Rep (ApiGatewayResponse body) x
$cto :: forall body x.
Rep (ApiGatewayResponse body) x -> ApiGatewayResponse body
$cfrom :: forall body x.
ApiGatewayResponse body -> Rep (ApiGatewayResponse body) x
Generic, Int -> ApiGatewayResponse body -> ShowS
forall body. Show body => Int -> ApiGatewayResponse body -> ShowS
forall body. Show body => [ApiGatewayResponse body] -> ShowS
forall body. Show body => ApiGatewayResponse body -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApiGatewayResponse body] -> ShowS
$cshowList :: forall body. Show body => [ApiGatewayResponse body] -> ShowS
show :: ApiGatewayResponse body -> String
$cshow :: forall body. Show body => ApiGatewayResponse body -> String
showsPrec :: Int -> ApiGatewayResponse body -> ShowS
$cshowsPrec :: forall body. Show body => Int -> ApiGatewayResponse body -> ShowS
Show)
instance Functor ApiGatewayResponse where
fmap :: forall a b.
(a -> b) -> ApiGatewayResponse a -> ApiGatewayResponse b
fmap a -> b
f ApiGatewayResponse a
v = ApiGatewayResponse a
v {$sel:apiGatewayResponseBody:ApiGatewayResponse :: b
apiGatewayResponseBody = a -> b
f (forall body. ApiGatewayResponse body -> body
apiGatewayResponseBody ApiGatewayResponse a
v)}
instance ToJSON body => ToJSON (ApiGatewayResponse body) where
toJSON :: ApiGatewayResponse body -> Value
toJSON = forall body. (body -> Value) -> ApiGatewayResponse body -> Value
apiGatewayResponseToJSON forall a. ToJSON a => a -> Value
toJSON
apiGatewayResponseToJSON :: (body -> Value) -> ApiGatewayResponse body -> Value
apiGatewayResponseToJSON :: forall body. (body -> Value) -> ApiGatewayResponse body -> Value
apiGatewayResponseToJSON body -> Value
bodyTransformer ApiGatewayResponse {body
Bool
Int
ResponseHeaders
apiGatewayResponseIsBase64Encoded :: Bool
apiGatewayResponseBody :: body
apiGatewayResponseHeaders :: ResponseHeaders
apiGatewayResponseStatusCode :: Int
$sel:apiGatewayResponseIsBase64Encoded:ApiGatewayResponse :: forall body. ApiGatewayResponse body -> Bool
$sel:apiGatewayResponseBody:ApiGatewayResponse :: forall body. ApiGatewayResponse body -> body
$sel:apiGatewayResponseHeaders:ApiGatewayResponse :: forall body. ApiGatewayResponse body -> ResponseHeaders
$sel:apiGatewayResponseStatusCode:ApiGatewayResponse :: forall body. ApiGatewayResponse body -> Int
..} =
[Pair] -> Value
object
[ Key
"statusCode" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Int
apiGatewayResponseStatusCode,
Key
"body" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= body -> Value
bodyTransformer body
apiGatewayResponseBody,
Key
"headers" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object (forall a b. (a -> b) -> [a] -> [b]
map (HeaderName, ByteString) -> Pair
headerToPair ResponseHeaders
apiGatewayResponseHeaders),
Key
"isBase64Encoded" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Bool
apiGatewayResponseIsBase64Encoded
]
mkApiGatewayResponse :: Int -> ResponseHeaders -> payload -> ApiGatewayResponse payload
mkApiGatewayResponse :: forall payload.
Int -> ResponseHeaders -> payload -> ApiGatewayResponse payload
mkApiGatewayResponse Int
code ResponseHeaders
headers payload
payload =
forall body.
Int -> ResponseHeaders -> body -> Bool -> ApiGatewayResponse body
ApiGatewayResponse Int
code ResponseHeaders
headers payload
payload Bool
False
headerToPair :: Header -> T.Pair
(HeaderName
cibyte, ByteString
bstr) = Key
k forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
v
where
k :: Key
k = (Text -> Key
K.fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
T.decodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. CI s -> s
CI.original) HeaderName
cibyte
v :: Text
v = ByteString -> Text
T.decodeUtf8 ByteString
bstr