使用AWS API Gateway构建补丁方法
Using AWS API Gateway to build a patch method
我正在使用 API 网关构建补丁方法。
然后 Integration Request - Mapping Template
我补充说:
{ "id": "$input.params('subscription-id')",
"env": "$stageVariables['env']",
"street": $input.json('street'),
"address_name": $input.json('address_name'),
"payment_day": $input.json('payment_day'),
}
作为patch http方式,不需要用户的API传递所有参数
因此,如果用户没有通过,例如payment_day,字段将是 ''
。 ''
可以是有效的值字段。所以我有两个选择:
- 在 payment_day 字段中输入 NULL 值。
- 从 JSON 请求中删除 payment_day。
是否可以在 API Gateway Integration Request -Mapping Template
上执行此操作?有人有解决方法吗?
您可以使用 Velocity Conditionals 仅输出可选值(如果存在)。
或者,如评论中所述,您可以使用 $input.json('$')
传递整个 JSON 主体,并处理 Lambda 函数内部是否存在。
我正在使用 API 网关构建补丁方法。
然后 Integration Request - Mapping Template
我补充说:
{ "id": "$input.params('subscription-id')",
"env": "$stageVariables['env']",
"street": $input.json('street'),
"address_name": $input.json('address_name'),
"payment_day": $input.json('payment_day'),
}
作为patch http方式,不需要用户的API传递所有参数
因此,如果用户没有通过,例如payment_day,字段将是 ''
。 ''
可以是有效的值字段。所以我有两个选择:
- 在 payment_day 字段中输入 NULL 值。
- 从 JSON 请求中删除 payment_day。
是否可以在 API Gateway Integration Request -Mapping Template
上执行此操作?有人有解决方法吗?
您可以使用 Velocity Conditionals 仅输出可选值(如果存在)。
或者,如评论中所述,您可以使用 $input.json('$')
传递整个 JSON 主体,并处理 Lambda 函数内部是否存在。