1
00:00:00,270 --> 00:00:06,510
In this video, we are going to enable request validation in API, Gateway Rest API.

2
00:00:06,840 --> 00:00:13,500
We can configure API Gateway to perform basic validation of API requests before proceeding with the

3
00:00:13,500 --> 00:00:14,730
integration request.

4
00:00:14,760 --> 00:00:17,220
We can see that this is the one request.

5
00:00:17,220 --> 00:00:20,760
Start with the method request and continue the integration request.

6
00:00:20,760 --> 00:00:26,220
So before the integration request we can put basic validation under the method request.

7
00:00:26,580 --> 00:00:33,540
When the validation face API gateway immediately fails to request and returns a 400 error response to

8
00:00:33,540 --> 00:00:34,380
the invoker.

9
00:00:34,470 --> 00:00:37,800
This is reduced to unnecessary calls to backend services.

10
00:00:38,610 --> 00:00:41,100
So API Gateway can perform the basic validation.

11
00:00:41,100 --> 00:00:47,880
This enables you and API gateway developer focus on the application specific validations in the back

12
00:00:47,880 --> 00:00:52,290
end for basic validation API Gateway verifies some conditions.

13
00:00:52,620 --> 00:00:56,070
For example, it is conditional request parameters.

14
00:00:56,070 --> 00:01:02,490
You're looking the URI created settings and headers of the incoming request and if there is any error,

15
00:01:02,520 --> 00:01:06,990
it is directly to turn back to response to the client application with the validation error.

16
00:01:07,530 --> 00:01:12,780
And also it is also checked for the payload and JSON secure request methods in the method request.

17
00:01:12,780 --> 00:01:18,390
But information in order to enable basic validation, we can specify validation rules in the request

18
00:01:18,390 --> 00:01:19,170
validator.

19
00:01:19,350 --> 00:01:25,230
Add the validator to the API to request validators and assign the validators to the individual API method.

20
00:01:25,560 --> 00:01:28,380
Let's try with our API gateway example.

21
00:01:28,500 --> 00:01:35,310
Please go to the resource section and come to the product and under the product select the gate method

22
00:01:35,310 --> 00:01:39,990
and you can see the one API gateway request integration.

23
00:01:39,990 --> 00:01:47,250
So we can click the method request now because we put the validation in here in order to avoid to go

24
00:01:47,270 --> 00:01:49,980
the integration request and go to downstream services.

25
00:01:49,980 --> 00:01:56,070
If there is an error in the payload, we can directly turn back to response to collide to avoid to unnecessary

26
00:01:56,070 --> 00:01:58,500
calls to downstream services.

27
00:01:58,500 --> 00:02:00,570
Click this method request page.

28
00:02:01,740 --> 00:02:06,730
This is the place of validation performs before redirecting to request to down system services.

29
00:02:06,750 --> 00:02:08,590
It can be lambda function or something.

30
00:02:08,590 --> 00:02:09,120
Yes.

31
00:02:09,120 --> 00:02:13,680
In the method request page we can select the request later.

32
00:02:13,680 --> 00:02:14,970
You can see in here.

33
00:02:15,000 --> 00:02:17,670
Click this icon to edit the request.

34
00:02:17,670 --> 00:02:18,480
Well later.

35
00:02:18,510 --> 00:02:22,080
And now we can put the well date body.

36
00:02:22,110 --> 00:02:25,120
We can see valid body and query sitting parameters.

37
00:02:25,140 --> 00:02:28,200
We can see the validate queries to improvements and headers.

38
00:02:28,200 --> 00:02:32,190
So I would like to select the request validate body.

39
00:02:32,460 --> 00:02:38,460
So after that, in the get request, we don't have body, so we choose last option B to create a string.

40
00:02:38,460 --> 00:02:43,380
For example, we can validate only query string because this is the get method.

41
00:02:43,380 --> 00:02:44,940
We don't have anybody.

42
00:02:44,940 --> 00:02:50,280
So select the validate query setting parameters and click this update button.

43
00:02:52,470 --> 00:02:52,790
Okay.

44
00:02:52,800 --> 00:02:53,580
Very good.

45
00:02:53,610 --> 00:02:57,900
After that, scroll down and go to your query parameters.

46
00:02:58,350 --> 00:03:01,200
You can see the query.

47
00:03:01,200 --> 00:03:02,720
You are requesting parameters.

48
00:03:02,730 --> 00:03:08,850
If we expand this section, we can add query sitting in here, click this button, and now I'm going

49
00:03:08,850 --> 00:03:12,120
to add a query setting, for example, category.

50
00:03:14,210 --> 00:03:15,020
And.

51
00:03:16,540 --> 00:03:18,040
Check this box.

52
00:03:19,070 --> 00:03:25,280
And we can also add the required for the category your query setting parameters.

53
00:03:25,540 --> 00:03:26,090
Okay.

54
00:03:26,090 --> 00:03:32,630
By this way, API Gateway will validate request before redirecting to the directing to the system services

55
00:03:32,930 --> 00:03:38,360
api gateway check the name parameter is then the category indicator setting parameters.

56
00:03:38,360 --> 00:03:43,610
If there is no category in the query strings, this will return any error.

57
00:03:43,850 --> 00:03:47,720
Okay, so let's test this example.

58
00:03:47,720 --> 00:03:53,030
In order to do that, we can go back to method execution path.

59
00:03:53,030 --> 00:04:01,220
So now we can click this test icon and I'm going to test without any providing query setting.

60
00:04:01,220 --> 00:04:05,290
Now we can provide queries in this box, but I'm not providing.

61
00:04:05,300 --> 00:04:09,710
Now scroll down and click the test button and see the error.

62
00:04:09,710 --> 00:04:15,960
So as you can see that the error comes from the a validation part, the message is missing required

63
00:04:15,960 --> 00:04:18,170
to request parameters, which is the category.

64
00:04:18,350 --> 00:04:23,630
So in order to validate this service, we should provide to category.

65
00:04:24,650 --> 00:04:26,930
Equal one, for example.

66
00:04:29,010 --> 00:04:29,310
Okay.

67
00:04:29,310 --> 00:04:34,980
Now click the test again and see this time this will be a return success response.

68
00:04:35,010 --> 00:04:36,840
So two is 200.

69
00:04:36,960 --> 00:04:43,700
And if you want to test with published URL, we have to deploy and test on the web browser on the postman.

70
00:04:43,710 --> 00:04:51,540
But this is the good way to test on directly API, get a management tool and see how validation works

71
00:04:51,540 --> 00:04:52,710
in our example.

72
00:04:53,180 --> 00:04:58,590
OC As you can see that we have enabled request validation and test in the API, Gateway Rest API.
