Overview
The External API plugin allows you to:- Make HTTP requests to external services during request processing
- Transform request data using field mappings
- Apply conditional logic based on external service responses
- Customize request headers and timeout settings
Configuration
Configuration Parameters
Required Settings
- endpoint: The URL of the external service
- stage: Must be set to
pre_request
Optional Settings
- method: HTTP method to use (default: “POST”)
- timeout: Request timeout duration (default: “5s”)
- headers: Custom headers to include in the request
- field_maps: Rules for mapping request fields to external API fields
- conditions: Validation rules based on the external API response
Field Mapping
Field mappings define how request data is transformed before being sent to the external service:Conditions
Conditions define validation rules based on the external service’s response:Available Operators
- eq: Equal to
- neq: Not equal to
- gt: Greater than
- lt: Less than
Response Handling
The plugin processes the external API response and:- Evaluates all configured conditions
- Returns an error if any condition with
stop_flow: true
is met - Includes the response body in the plugin response for downstream processing
Error Response
When validation fails, the plugin returns:Example: Content Moderation
Example: Custom Validation
Best Practices
- Timeout Configuration
- Set appropriate timeouts based on external service SLAs
- Consider the impact on request latency
- Use shorter timeouts for critical paths
- Error Handling
- Provide clear error messages in conditions
- Consider fallback behavior when external service is unavailable
- Monitor external service reliability
- Security
- Use environment variables for sensitive headers
- Validate external service certificates
- Implement proper authentication
- Performance
- Keep field mappings minimal
- Use efficient condition evaluations
- Monitor external service response times