[英]How to access AWS API Gateway Models from iOS
AWS Model schema AWS模型架构
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "QuestionsModel",
"type": "array",
"items": {
"type": "object",
"properties": {
"placeholder" : { "type":"string" },
"type" : { "type":"string" },
"order": { "type": "integer" },
"prompt": { "type": "string" },
"section_name": { "type": "string" }
}
}
}
AWS Integration Response - Mapping Template - application/json AWS集成响应-映射模板-application / json
Mapping using Velocity Template Language An array... 使用Velocity模板语言进行映射数组...
#set($inputRoot = $input.path('$'))
[
#foreach($elem in $inputRoot)
{
"type" : "$elem.type",
"placeholder" : "$elem.placeholder",
"order" : "$elem.order",
"prompt" : "$elem.prompt",
"section_name" : "$elem.section_name"
}
#if($foreach.hasNext),#end
#end
]
AWS Lambda function AWS Lambda函数
def lambda_handler(event, context):
client = boto3.client('dynamodb')
response = client.scan(
TableName='Question',
AttributesToGet=[
'type',
'order',
'section_name',
'prompt',
'placeholder'])
return = response['Items']
iOS app the Model iOS应用程式模型
The iOS Model has a field type
of type NSString populated with the value {S=Hello World}
iOS模型的字段type
为NSString,其中填充了值{S=Hello World}
I'd rather the iOS field be equal to Hello World
saving me parsing {S=*}
我希望iOS字段等于Hello World
让我解析{S=*}
Where am I going wrong? 我要去哪里错了?
Did you set up the response model in the method response? 您是否在方法响应中设置了响应模型? Here is the basic walkthrough provided by API Gateway. 这是API Gateway提供的基本演练。 http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-models.html http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-models.html
I pinned down the answer in another question . 我把答案固定在另一个问题上 。
Undocumented but you can simply specify the type after the field name in a mapping template: 未公开,但您只需在映射模板中的字段名称后指定类型:
#set($inputRoot = $input.path('$'))
[
#foreach($elem in $inputRoot)
{
"field1" : "$elem.field1.S",
"field2" : $elem.field2.N
}#if($foreach.hasNext),#end
#end
]
Note that string fields need to be delimited in quotes and numbers don't. 请注意,字符串字段需要用引号分隔,而数字则不需要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.