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 functionsmcpServerHandler- Model Context Protocol server handleropenApiSpecHandler- Serve OpenAPI specificationsredirectHandler- HTTP redirectsurlForwardHandler- Forward requests to another URLurlRewriteHandler- Rewrite request URLswebSocketHandler- WebSocket connectionswebSocketPipelineHandler- WebSocket with pipeline support
Usage in Routes
Handlers are configured in your route definition:
Code
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
Conditional Redirects
Code
Lambda Integration
Code
Custom Handler Implementation
If built-in handlers don't meet your needs, you can create custom handlers:
Code
Handler Options
Most handlers accept options to configure their behavior:
Code
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
Last modified on