A one-click Deploy to Cloudflare template gets you a working Worker on Cloudflare's global edge network — one fetch handler, two secrets, sub-second response from anywhere in the world. No containers, no cold starts, no separate dashboard.
Cloudflare Workers are just an exported fetch handler. The Posthawk SDK is fetch-based with zero Node-only dependencies, so it slots in without any compatibility flags.
Need a queue or a cron? Add a queue or scheduled handler alongside fetch. The README covers both.
// src/index.ts
import { Posthawk } from 'posthawk';
interface Env {
POSTHAWK_API_KEY: string;
POSTHAWK_FROM_EMAIL: string;
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
if (request.method !== 'POST') {
return new Response('POST { email, name } as JSON.', { status: 200 });
}
const { email, name } = await request.json();
const posthawk = new Posthawk(env.POSTHAWK_API_KEY);
const { data, error } = await posthawk.emails.send({
from: env.POSTHAWK_FROM_EMAIL,
to: email,
subject: `Welcome, ${name}!`,
html: `<h1>Hey ${name}</h1><p>Sent from the edge.</p>`,
});
if (error) return Response.json({ error }, { status: 400 });
return Response.json({ id: data.id });
},
} satisfies ExportedHandler<Env>;Cloudflare forks the posthawk-dev/cloudflare-workers-starter template, walks you through a setup screen, and deploys the Worker to its global edge network.
Run wrangler secret put POSTHAWK_API_KEY and POSTHAWK_FROM_EMAIL — or set them in the dashboard under Settings → Variables and Secrets. No env files in production.
You get a *.workers.dev URL. POST { email, name } as JSON and Posthawk sends the welcome email. Zero cold start, sub-second response.
Cloudflare Workers run in V8 isolates, not containers. No warm-up time — your endpoint is ready at the edge nearest the caller, always.
Your Worker runs on 300+ Cloudflare locations. The HTTP roundtrip from browser to edge is single-digit milliseconds, anywhere in the world.
wrangler dev gives you hot reload locally, wrangler deploy ships to production. Observability + tail logging built in via wrangler.jsonc.
The SDK unwraps every response into { data, error }. Surface error.requestId from your Worker so callers can quote it in support requests.
Click the button. Set two secrets. POST JSON. Done.
I use analytics cookies to understand how you use the site and improve your experience. Privacy Policy