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

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
    }
  ]
}

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.