Documentation

API Documentation

A real-time trivia system designed for consistency and replayability.

Indexed Nov 5, 2026

Quick Links

Frontend

React + Vite with real-time state handling

Backend

Next.js API routes powering trivia logic

Github

Repository with all of the Source Code


Core System

Problem

Traditional trivia systems frequently repeat questions across sessions.

Mechanism

A session-based token is issued and attached to all requests to opentdb.

Outcome

Each session (6 hours) guarantees unique question delivery.


Token Flow

Client token request → Request proxied by Next.js → Token issued by opentdb.


Implementation

  • Generate a session token

  • Store token on client

  • Attach token to all requests

  • Reset after expiration (~6 hours)


API

/api/trivia

warn

Get a list of questions. Amount is how many questions will be returned

GET /api/trivia?amount={value}

Json Schema

{
  "amount": number,
  "data": {
    "response_code": number,
    "results": [
      {
        "type": string,
        "difficulty": string,
        "category": string,
        "question": string,
        "correct_answer": string,
        "incorrect_answers": string[]
      }
    ]
  }
}

API request

GET https://backend.triviaup.adityabaindur.com/api/trivia

Request fields (as configured in the original documentation):

[
    {
      name: 'amount',
      label: 'Amount',
      type: 'range',
      location: 'query',
      min: 1,
      max: 20,
      step: 1,
      defaultValue: 5,
      required: true,
    },
    {
      name: 'difficulty',
      label: 'Difficulty',
      type: 'select',
      location: 'query',
      options: ['easy', 'medium', 'hard'],
    },
    {
      name: 'type',
      label: 'Question Type',
      type: 'select',
      location: 'query',
      options: [
        { label: 'Multiple Choice', value: 'multiple' },
        { label: 'True / False', value: 'boolean' },
      ],
    },
    {
      name: 'token',
      label: 'Session Token',
      type: 'text',
      location: 'query',
      placeholder: 'Optional',
    },
  ]

/api/trivia/token

warn

Call once per session. Reuse across requests. Valid for upto 6 hours

GET /api/trivia/token

Json Schema

{
  "data": {
    "response_code": number,
    "response_message": string,
    "token": string
  },
  "token": string
}

Generate Token

GET https://backend.triviaup.adityabaindur.com/api/trivia/token