In this lab, we will learn how to validate an API request.
Overview
- Source: API Gateway – REST API
- Route: GET /greet?name=abc
- Target: Mock
- Returns the validation error when the required query string ‘name’ does not exist
1. API Gateway – Create an API
- REST API -> Click “Build“
- API Details
- Check “New API“
- Name: “Greeting“
- Endpoint type: “Regional“
- Click “Create API“
2. API – Create Resource
- Click the “API” menu on the left pane
- Click the “Greeting” API
- Click “Create resource”
- Resource name: “greet“
- Click “Create resource“
- Click “Create resource”
3. API – Create Method
- Select the “greet” resource
- Click “Create method”
- Method type: “GET“
- Integration type: “Mock”
- Click “Create method“
4. API – Mock Result
- Select the “GET” method
- Select the “Integration response” tab
- Under the “Mapping templates“, click “Edit”
- Update the template body and save the template
{
"statusCode": 200,
"message": "Hello! Success!"
}
5. API – Add a Query string validation
- Select the “GET” method
- Select the “Method request” tab
- Click “Edit”
- Request Validator: “Validate query string parameters and headers“
- Under the “URL query string parameters”, click “Add query string”
- Name: “name“
- Check “Required“
- Click “Save“
6. API – Test – Success
- Select the “GET” method
- Select the “Test” tab
- Query String: “name=abc“
- Click “Test“
7. API – Test – Validation Error
- Select the “GET” method
- Select the “Test” tab
- Query String: empty
- Click “Test“
- You are getting the BadRequestException response
- “Missing required request parameters“

