forked from riteshbehal/Assignments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidate request body.txt
71 lines (53 loc) · 1.42 KB
/
Validate request body.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Create Lambda Function with below code
Create API Gateway
Create Post Method
Call post method from Postman (While calling it from browser it should give you error)
In last example, I have created request header validation and this example is for request body validation
For body validation you have to create model
Go to Model
Add Model Name
Add content type as "application/json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Employee Status",
"type": "object",
"properties": {
"status": { "type": "string", "enum": ["permanent", "contractors"]}
},
"required" : ["status"]
}
Create Model
Go Back to Post method
Method Request
Change Request validator to "validate body"
Add Request Body
add content type "application/json" and Choose model name "body validation" and save
Lambda Code :
import json
def lambda_handler(event, context):
response = {
"contractors": [
{
"On Site": 70,
"Total Contractors": 200
}
],
"permanent": [
{
"On Site": 20,
"Total Employees": 2000
}
]
}
# TODO implement
return {
'statusCode': 200,
'body': response[event["status"]]
}
Through postman we can test using post hit
{
"status": "permanent"
}
{
"status": "contractors"
}