Skip to main content
Response functions modify the output after Request functions complete. They run automatically and can enhance responses with analytics, security, personalization, and business logic.

When to Use

  • Add analytics tracking to all responses
  • Apply security headers and CORS policies
  • Insert personalized content and recommendations
  • Apply dynamic pricing and discounts

What They Do

  • Receive both request and response data
  • Modify response headers, body, and status
  • Add computed fields and enrichments
  • Transform data before sending to users

How Response Functions Work

  1. Request function completes and generates initial response
  2. Response function automatically triggered with request and response data
  3. Function modifies response headers, body, or status as needed
  4. Enhanced response sent to user with improvements

Response Function Examples

  • Analytics Tracking
  • Dynamic Discounts
  • Security Headers
  • Personalization
Add tracking pixels and analytics data to responses:Sample URL:
API Endpoint
https://hub.ollie.app/https://api.mystore.com/products/search?search=laptop
{
  "products": [
    {
      "id": "prod_123",
      "name": "MacBook Pro",
      "price": 1899.99
    }
  ]
}
Enhanced Response
{
  "products": [
    {
      "id": "prod_123",
      "name": "MacBook Pro",
      "price": 1899.99
    }
  ],
  "analytics": { 
    "trackingId": "sess_abc123def456", 
    "correlationId": "corr_789xyz012", 
    "userSegment": "premium", 
    "conversionFunnel": "product_view", 
    "sessionStart": "2024-01-12T10:25:30.456Z"
  } 
}
Enhanced Headers:
Content-Type: application/json
X-Tracking-Id: sess_abc123def456 // [!code ++]
X-Request-Time: 2024-01-12T10:30:45.123Z // [!code ++]
X-User-Segment: premium // [!code ++]
X-Session-Duration: 315 // [!code ++]
What Ollie Hub adds:
  • βœ… Comprehensive user behavior tracking
  • βœ… Analytics data injection for BI tools
  • βœ… Request correlation for debugging
  • βœ… User segmentation for personalization
  • βœ… Conversion funnel tracking
  • βœ… Session analytics

Best Practices

Fail Gracefully

Always return the original response if your enhancement fails. Don’t break the user experience.

Keep It Fast

Response functions should be lightweight. Heavy processing can slow down responses.

Be Selective

Not every response needs enhancement. Use conditional logic to enhance only when needed.

Log Errors

Log enhancement errors for debugging, but don’t let them affect the user’s response.

Next Steps

Pro Tip: Response functions are perfect for adding cross-cutting concerns like analytics, security, and personalization without modifying your core business logic. Check out our Best Practices guide for implementation patterns.