Astro
Node.js — server endpoints / SSR

Flowmails + Astro

Astro's API routes work like any other HTTP server endpoint. The SDK runs in the Node / Workers runtime Astro deploys to.

Step 1

Install the SDK

installbash
pnpm add @flowmails/flowmails-sdk

Step 2

Send your first message

sendtypescript
// src/pages/api/contact.ts
import type { APIRoute } from "astro";
import { Flowmails } from "@flowmails/flowmails-sdk";

export const POST: APIRoute = async ({ request }) => {
  const body = await request.json();
  const fm = new Flowmails({ apiKey: import.meta.env.FLOWMAILS_API_KEY });
  const result = await fm.send({
    from: "hello@yourdomain.com",
    to: body.email,
    subject: "Welcome",
    text: `Hi ${body.name}, thanks for signing up.`,
  });
  return new Response(JSON.stringify({ id: result.id }), {
    headers: { "Content-Type": "application/json" },
  });
};

Prerequisites

What you need first

  • Astro 4+ with an SSR adapter
  • FLOWMAILS_API_KEY in the environment

Runtime notes

Things to know on Astro

Use `import.meta.env.FLOWMAILS_API_KEY` for the build-time-public env, and `process.env.FLOWMAILS_API_KEY` for runtime secrets — pick the right one for your adapter.

Other integrations

All Flowmails integrations