Request functions handle incoming HTTP requests from users. They’re your main API endpoints that process user interactions, validate data, and execute business logic.

When to Use

  • User authentication and registration
  • Form submissions and data processing
  • API endpoints and webhook handlers
  • E-commerce transactions and payments

What They Do

  • Receive HTTP requests (GET, POST, PUT, DELETE)
  • Validate and process input data
  • Execute business logic
  • Return responses to users

How Request Functions Work

  1. User makes HTTP request to your function via hub URL
  2. Hub routes request to your function with authentication
  3. Function processes request data and executes business logic
  4. Response returned to user with any Hub enhancements

Request Function Examples

Best Practices

Validate Early

Always validate input data first. Return helpful error messages for invalid requests.

Handle Errors Gracefully

Use try-catch blocks and return appropriate HTTP status codes and error messages.

Keep Functions Focused

Each function should handle one specific endpoint or operation. Don’t try to do everything.

Use Proper Status Codes

Return correct HTTP status codes: 200 for success, 400 for bad input, 404 for not found, etc.

Next Steps

Pro Tip: Request functions work great with Response functions to add analytics, security headers, and custom transformations automatically. Check out our Best Practices guide for implementation patterns and security tips.