【发布时间】:2016-09-14 06:43:31
【问题描述】:
有没有办法不在方法请求和集成请求中定义 URL 查询字符串参数并将查询字符串传递给 HTTP 代理?
例如,如果是 https://{api id}-api.us-east-1.amazonaws.com/test/user?start=1&end=10
查询字符串 1.开始 2.结束
如果我将 URL Query 字符串参数放入 Method request 和 Integration request 中,那么我可以同时获取这两个查询字符串。但是,如果我不添加它们并在邮递员中发出请求,那么在后端我不会得到两个查询字符串。
我想获取查询字符串而不在方法请求和集成请求中定义。原因是如果有很多我不想输入所有参数。
有没有办法做到这一点?
我正在使用 HTTP 代理,这是我正在使用的模板映射。 (实际上是 Method Request passthrough 下拉菜单)。
#set($allParams = $input.params())
{
"body-json" : "$input.json('$')",
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
#if($foreach.hasNext),#end
#end
},
"context" : {
"account-id" : "$context.identity.accountId",
"api-id" : "$context.apiId",
"api-key" : "$context.identity.apiKey",
"authorizer-principal-id" : "$context.authorizer.principalId",
"caller" : "$context.identity.caller",
"cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
"cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
"cognito-identity-id" : "$context.identity.cognitoIdentityId",
"cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
"http-method" : "$context.httpMethod",
"stage" : "$context.stage",
"source-ip" : "$context.identity.sourceIp",
"user" : "$context.identity.user",
"user-agent" : "$context.identity.userAgent",
"user-arn" : "$context.identity.userArn",
"request-id" : "$context.requestId",
"resource-id" : "$context.resourceId",
"resource-path" : "$context.resourcePath"
}
}
【问题讨论】:
标签: amazon-web-services aws-api-gateway