You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Source-agnostic types that work with any Lambda trigger
116
+
- Type guards for safe context type checking
107
117
- Full type inference for request and response objects
108
118
- Generic type parameters for response types
109
119
- Support for API Gateway and ALB contexts
@@ -112,6 +122,74 @@ Key TypeScript Features:
112
122
- Automatic type inference for all HTTP methods
113
123
- Type safety for cookies, headers, and other API features
114
124
125
+
## Type Guards
126
+
127
+
Lambda API provides type guards to safely work with different request sources:
128
+
129
+
```typescript
130
+
import {
131
+
isApiGatewayContext,
132
+
isApiGatewayV2Context,
133
+
isAlbContext,
134
+
isApiGatewayRequest,
135
+
isApiGatewayV2Request,
136
+
isAlbRequest
137
+
} from'lambda-api';
138
+
139
+
// Check request context type
140
+
if (isApiGatewayContext(req.requestContext)) {
141
+
// TypeScript knows this is APIGatewayContext
142
+
console.log(req.requestContext.identity);
143
+
}
144
+
145
+
// Check entire request type
146
+
if (isApiGatewayRequest(req)) {
147
+
// TypeScript knows this is Request<APIGatewayContext>
148
+
console.log(req.requestContext.identity);
149
+
}
150
+
```
151
+
152
+
## Handling Multiple Request Sources
153
+
154
+
Lambda API provides type-safe support for different AWS Lambda triggers. You can write source-specific handlers or use source-agnostic handlers that work with any trigger:
- Source-agnostic types that work with any trigger
190
+
- Full type safety for source-specific properties
191
+
- Automatic payload format detection
192
+
115
193
## Why Another Web Framework?
116
194
117
195
Express.js, Fastify, Koa, Restify, and Hapi are just a few of the many amazing web frameworks out there for Node.js. So why build yet another one when there are so many great options already? One word: **DEPENDENCIES**.
0 commit comments