# middy

Published articles for middy.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## AWS API Gateway's Request Validation: Navigating the Quirks

DevFeed: [AWS API Gateway's Request Validation: Navigating the Quirks](<https://devfeed.tech/articles/aws-api-gateway-s-request-validation-navigating-the-quirks-23894.md>)

Original publisher: [Read original article](<https://medium.com/smg-real-estate/aws-api-gateways-request-validation-navigating-the-quirks-38285cb0a1c1?source=rss----2186e5b9bd8f---4>)

Author: Thomas Klein

Published: 2024-08-09T12:07:11Z

Content type: tutorial

Language: en

Sources: [Homegate Engineering Blog - Medium](<https://devfeed.tech/sources/homegate-engineering-blog-medium.md>)

Topics: [Amazon API Gateway](<https://devfeed.tech/topics/amazon-api-gateway.md>), [Amazon Web Services](<https://devfeed.tech/topics/aws.md>), [API](<https://devfeed.tech/topics/api.md>), [gateway](<https://devfeed.tech/topics/gateway.md>), [JSON Schema](<https://devfeed.tech/topics/json-schema.md>), [TypeScript](<https://devfeed.tech/topics/typescript.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [enum](<https://devfeed.tech/topics/enum.md>), [HTTP](<https://devfeed.tech/topics/http.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [api-gateway](<https://devfeed.tech/tags/api-gateway.md>), [aws](<https://devfeed.tech/tags/aws.md>), [aws-api-gateway](<https://devfeed.tech/tags/aws-api-gateway.md>), [aws-lambda](<https://devfeed.tech/tags/aws-lambda.md>), [enum](<https://devfeed.tech/tags/enum.md>), [gateway](<https://devfeed.tech/tags/gateway.md>), [handler](<https://devfeed.tech/tags/handler.md>), [http](<https://devfeed.tech/tags/http.md>), [json](<https://devfeed.tech/tags/json.md>), [json-schema](<https://devfeed.tech/tags/json-schema.md>), [middleware](<https://devfeed.tech/tags/middleware.md>), [middy](<https://devfeed.tech/tags/middy.md>), [tests](<https://devfeed.tech/tags/tests.md>), [type-safety](<https://devfeed.tech/tags/type-safety.md>), [typescript](<https://devfeed.tech/tags/typescript.md>), [validation](<https://devfeed.tech/tags/validation.md>), [zod](<https://devfeed.tech/tags/zod.md>)

### AI overview

This tutorial examines AWS API Gateway request validation. It explains that query-parameter presence is checked, but enum values may not be enforced, while POST and PUT payloads are validated with JSON Schema Draft 4. It also discusses generic error messages and TypeScript-based validation approaches.

### Source excerpt

AWS API Gateway's request validation follows a specific set of rules that developers should be aware of when setting up their APIs. While it offers some validation features, it's important to understand its scope and limitations. Let's examine how it works with a common API configuration: parameters: - name: offerType in: query required: true description: RENT or BUY schema: type: string enum: - RENT - BUY With this configuration, API Gateway diligently checks for the presence of the query parameter, returning an HTTP 400 error if it's missing. However, it falls short when it comes to validating the actual value. Surprisingly, it would accept "KERMIT" without batting an eye, despite the clear enum specification. This behavior, while documented, can be a source of frustration for developers expecting more comprehensive validation. Interestingly, API Gateway shows more validation prowess with POST and PUT requests. It validates request payloads using JSON Schema Draft 4, demonstrating a somewhat inconsistent approach to input validation across different HTTP methods. Even when it does catch an error, API Gateway's feedback is less than illuminating. Instead of specific error details, you're met with a generic {"message": "Invalid request body"}. For more information, you'll need to dig into the associated log streams, which isn't ideal for surfacing error details in API responses. Example output in AWS console from a failed request validation when a body request validator is setup. API Gateway's validation is handy, but it leaves a lot to be desired. Developers often need to add extra checks for a truly robust API. While API Gateway supports various integrations and Lambda languages, let's focus on TypeScript. TypeScript's strong typing and runtime checks can catch issues early, sparing your users from cryptic error messages. Let's explore how to use this to make your API smarter and your users happier. Option 1: DIY Validation (AKA The "I've Got Trust Issues" Approac