Trivia Quiz Template
- Next.js
- TypeScript
Ten-question trivia rounds with instant answers, a score, a streak and your best round.
A Next.js trivia game. Play rounds of ten multiple-choice and true-or-false questions, tap an answer to see right away whether you got it, and keep your score, a streak and your best round on the device. The next question loads while you read the current one. Use it for a quiz night or a classroom warm-up, or lift the route to add trivia to a chat bot, newsletter or app.

What it does
- Rounds of ten
- A progress bar, a running score and a streak, with a summary and your best round at the end.
- Instant answers
- Your pick turns green or red the moment you tap, and the right answer is always shown.
- No waiting
- The next question is fetched while you read this one, so Next question is instant.
- Clean options
- The route strips the API’s A–D labels and marks the right option, so the page draws its own buttons.
- Keeps your key private
- The browser only calls your own API route, which holds the key and limits each visitor to 10 questions a minute.
How it works
The API route: it calls Trivia Generator, strips the option letters and marks the right answer.
/** GET /api/question: one multiple-choice question from Trivia Generator. */
export async function GET(request: Request) {
const blocked = guard(request);
if (blocked) return blocked;
return respond(async () => {
const raw = await callApi<Raw>('trivia');
const options = raw.options.map(unlabel);
const answer = raw.answer.trim().toLowerCase();
let correct = options.findIndex((o) => o.trim().toLowerCase() === answer);
if (correct < 0) correct = options.findIndex((o) => o.toLowerCase().includes(answer));
const question: Question = { question: raw.question, options, correct, category: raw.category };
return question;
});
}Deploy it
- Get a free API key
The free plan includes 200 credits a month, no card needed. Create your key.
- Deploy it
Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for
APIVERVE_API_KEY: paste your key there. - Open your app
Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.
Try the Trivia Generator API — the call this template makes
No key required to try it. Get a key to use it in your app.
{
"status": "ok",
"error": null,
"data": {
"question": "Is the Pink Cadillac the trademark of Mary Kay beauty products?",
"answer": "Yes",
"options": [
"A Yes",
"B No"
],
"category": "general"
}
}