Templates / APIs
Waitlist signup API with position and duplicate checks
An endpoint that adds emails to a waitlist, ignores duplicates, tells people their position — plus a public count for your landing page.
A launch page needs exactly one backend feature: collect emails. This keeps them in a table keyed by email (so duplicates are impossible), returns a position for the “you’re #214” moment, and serves a count for social proof.
Build it with Wisp
Type this into Wisp, or press Build this — it writes the code below, deploys it and gives you a URL:
A POST /join endpoint that adds { email, source } to a waitlist table keyed by lowercase email, returns the person’s position and whether they were already on it, and a GET /waitlist-count endpoint that returns the total.
The code
POST /join · API
import { table } from 'wisp';
export async function handler(req) {
const email = String(req.body?.email ?? '').trim().toLowerCase();
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) return { status: 400, body: { error: 'Enter a valid email' } };
const waitlist = table('waitlist');
const existing = await waitlist.get(email);
if (!existing) await waitlist.put(email, { email, source: String(req.body?.source ?? 'site').slice(0, 50) });
const row = existing ?? (await waitlist.get(email));
// Position = how many joined before this person, plus one.
const position = (await waitlist.count((r) => r.createdAt < row.createdAt)) + 1;
return { body: { position, alreadyJoined: !!existing } };
}
GET /waitlist-count · API
import { table } from 'wisp';
export async function handler() {
return { body: { count: await table('waitlist').count({}) } };
}
Try it
curl -X POST https://<your-project-url>/join -H "content-type: application/json" -d '{"email":"ada@example.com","source":"twitter"}'
curl https://<your-project-url>/waitlist-count
Turn on edge caching for waitlist-count (60 seconds) so a busy landing page doesn’t count on every visit.
How it works
- Using the email as the row id makes duplicates impossible without a separate check-and-insert race.
- Position counts earlier signups by
createdAt. - Table scans are fine up to about 10,000 rows; past that, keep a running counter with
kv.incr.
Variations
- Send a welcome email with Resend.
- Give each signup a referral code and move people up when friends join.
- Export the list as CSV from a private function.
Questions
Can I see the list? Yes — Storage → Tables in the Wisp console shows every row, newest first.
Build it with Wisp — free trial