0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【AWS】API Gatewayで配列パラメーターを受取る

Posted at

API Gateway(REST API)で配列のクエリパラメーターを受け取れませんでしたので、その解決方法をメモします。

前提

API GatewayとLambdaプロキシ統合で使用

multiValueQueryStringParametersを受取る(node.js)

ローカルの場合リクエストからクエリパラメーター配列を受け取れますが、API gateway経由で配列を受け取れないそうです。そのため、eventのmultiValueQueryStringParametersから配列パラメーターを受け取ります。

const express = require('express')
const router = express.Router()
router.get('/demo', [
], (req, res, next) => {
  (async () => {
    // 配列パラメーター
    let areaCodes
    if (req.apiGateway) {
      // api Gateway
      areaCodes = req.apiGateway.event.multiValueQueryStringParameters.areaCodes
    } else {
      // ローカル
      areaCodes = req.query.areaCodes
    }
  })().catch(e => next(e))
})
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?