Slide 10
Slide 10 text
Copyright © 2015-2023 ALTERBOOTH inc. All Rights Reserved.
public APIGatewayHttpApiV2ProxyResponse LambdaMathAdd(APIGatewayHttpApiV2ProxyRequest request,
ILambdaContext context)
{
if (!request.PathParameters.TryGetValue("x", out var xs))
{
return new APIGatewayHttpApiV2ProxyResponse
{
StatusCode = (int)HttpStatusCode.BadRequest };
}
if (!request.PathParameters.TryGetValue("y", out var ys))
{
return new APIGatewayHttpApiV2ProxyResponse
{
StatusCode = (int)HttpStatusCode.BadRequest
};
}
var x = int.Parse(xs);
var y = int.Parse(ys);
return new APIGatewayHttpApiV2ProxyResponse
{
StatusCode = (int)HttpStatusCode.OK, Body = (x + y).ToString(),
Headers = new Dictionary≪string, string> { { "Content-Type", "text/plain" } }
};
}
リクエストのパスパラメータをチェック
して、xを取得
なければBadRequestを返す
リクエストのパスパラメータをチェック
して、yを取得
なければBadRequestを返す
x + yの結果をBodyに入れて、200 OKを返
す
Content-typeはtext/plain