Handlers
Zuplo provides several built-in handlers for common API gateway scenarios. These handlers can be used directly in your route configuration without writing custom code.
Available Handlers
Request Handlers
- awsLambdaHandler - Invoke AWS Lambda functions
- mcpServerHandler - Model Context Protocol server handler
- openApiSpecHandler - Serve OpenAPI specifications
- redirectHandler - HTTP redirects
- urlForwardHandler - Forward requests to another URL
- urlRewriteHandler - Rewrite request URLs
- webSocketHandler - WebSocket connections
- webSocketPipelineHandler - WebSocket with pipeline support
Usage in Routes
Handlers are configured in your route definition:
Code(json)
Handler Types
1. Proxy Handlers
These handlers forward requests to other services:
urlForwardHandler
- Simple URL forwardingurlRewriteHandler
- URL rewriting with pattern matchingawsLambdaHandler
- AWS Lambda integration
2. Response Handlers
These handlers generate responses directly:
redirectHandler
- HTTP redirectsopenApiSpecHandler
- OpenAPI documentationmcpServerHandler
- MCP protocol responses
3. Protocol Handlers
These handlers support specific protocols:
webSocketHandler
- Basic WebSocket supportwebSocketPipelineHandler
- WebSocket with policy pipeline
Common Patterns
Dynamic URL Forwarding
Code(json)
Conditional Redirects
Code(json)
Lambda Integration
Code(json)
Custom Handler Implementation
If built-in handlers don't meet your needs, you can create custom handlers:
Code(ts)
Handler Options
Most handlers accept options to configure their behavior:
Code(json)
Error Handling
Built-in handlers follow standard error handling patterns:
- Network errors return 502 Bad Gateway
- Invalid configurations return 500 Internal Server Error
- Client errors are passed through from upstream services
Performance Considerations
- Built-in handlers are optimized for performance
- Handlers run at the edge for low latency
- Connection pooling is handled automatically
- Automatic retries for transient failures (where appropriate)
See Also
- Custom Handlers - Building custom handlers
- Route Configuration - Configuring routes
- Policies - Adding policies to handlers