Function Types
Every function has a type that determines when and how it runs. Palpaca supports two function types: Trigger and Scheduled.
Trigger Functions (HTTP)
Section titled “Trigger Functions (HTTP)”A trigger function runs whenever it receives an incoming HTTP request. This makes it ideal for:
- Webhooks — receive events from HubSpot, Stripe, Slack, or any service that sends webhooks
- API endpoints — expose a custom API that other systems can call
- Form handlers — process form submissions from external websites
Trigger functions use standard HTTP request methods:
export default { async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> { const url = new URL(request.url) // Handle the request return new Response("OK") }}You can route by HTTP method (GET, POST, etc.) and URL path inside the handler.
Scheduled Functions (Cron)
Section titled “Scheduled Functions (Cron)”A scheduled function runs automatically at intervals you define using a cron expression. Use these for:
- Data syncs — periodically pull data from external systems into HubSpot
- Reports — generate and send reports on a schedule
- Cleanup tasks — archive old records, update stale properties
- Monitoring — check external services and alert when something is wrong
Scheduled functions use the scheduled handler:
export default { async scheduled(controller: ScheduledController, env: Env, ctx: ExecutionContext): Promise<void> { console.log("Running scheduled task:", controller.cron) // Do work here }}Common Cron Patterns
Section titled “Common Cron Patterns”| Pattern | Runs |
|---|---|
* * * * * | Every minute |
*/15 * * * * | Every 15 minutes |
0 * * * * | Every hour |
0 */6 * * * | Every 6 hours |
0 9 * * 1-5 | Weekdays at 9:00 AM UTC |
0 0 * * * | Daily at midnight UTC |
0 0 1 * * | First day of each month |
You set the cron expression when creating the function. The schedule is configured during deployment.
Choosing a Type
Section titled “Choosing a Type”If your function needs to respond to external events in real time, choose Trigger. If it needs to run on its own at regular intervals, choose Scheduled. Each function can only have one type — it cannot be both.