This is a simple trivia API built as a Spin app using the JavaScript SDK. The API serves random trivia questions from the Open Trivia Database (OpenTDB), providing users with trivia questions along with multiple-choice answers.
- Built with Spin and the JavaScript SDK.
- Fetches random trivia questions from the OpenTDB API.
- Returns trivia questions along with multiple choices, including the correct answer.
- Implements a simple REST API using itty-router.
- Spin v3.0 or newer
- Node.js (v14 or later)
- npm (v6 or later)
Clone the repository:
git clone https://github.com/macolso/trivia-api.gitNavigate into the project directory:
cd trivia-apiInstall dependencies:
npm installStart the server:
spin build --upThe server will be running on http://localhost:3000/api.
curl localhost:3000/api- GET /trivia Returns a random trivia question along with multiple-choice answers. Example response:
{
"question": "When was Nintendo founded?",
"choices": [
"September 23rd, 1889",
"November 16th, 1894",
"April 1st, 1888",
"July 7th, 1890"
],
"answer": "September 23rd, 1889"
}