Complete solution (100% reference)
index.html
- Main HTML pagescript.js
- JavaScript logicstyles.css
- Styling and layoutpackage.json
- Dependenciessetup.sh
- Setup scriptREADME.md
- Instructions (below)๐ก Download the ZIP, extract it, and follow the instructions below to get started!
A complete Express.js REST API for managing quests, players, and categories in a gamified todo system.
This activity requires npm dependencies (5.8MB node_modules) that are NOT included in the ZIP file.
# 1. Extract the ZIP file
unzip activity-11-quest-api.zip
cd activity-11-quest-api
# 2. Install dependencies (REQUIRED!)
npm install
# 3. Start the server
npm start
# 4. Open test.html in your browser
Why node_modules is excluded:
Required packages: express, cors, express-rate-limit, helmet, morgan
Note for Teachers: This is the complete reference implementation. Students receive a version with TODOs to complete.
test.html
to interact with your APIactivity-11-quest-api/
โโโ server.js # Main Express server
โโโ routes/
โ โโโ quests.js # Quest management endpoints
โ โโโ players.js # Player profile and stats
โ โโโ categories.js # Quest categories and suggestions
โโโ middleware/ # Custom middleware (ready for expansion)
โโโ test.html # Interactive API testing interface
โโโ package.json # Dependencies and scripts
โโโ README.md # This file
After completing this activity, you'll understand:
Get all quests with filtering and sorting options.
Query Parameters:
status
- Filter by quest status (pending, in_progress, completed)priority
- Filter by priority (low, medium, high, critical)category
- Filter by category (work, health, personal, learning, creative)tags
- Filter by tags (comma-separated)difficulty
- Filter by difficulty (easy, medium, hard)sort_by
- Sort field (created_at, priority, deadline, xp_reward)order
- Sort order (asc, desc)limit
- Maximum results (1-50)Example:
GET /api/quests?status=pending&priority=high&sort_by=deadline&limit=10
Get detailed information about a specific quest.
Features:
Mark a quest as completed and calculate rewards.
Features:
Create a new quest with custom parameters.
Required Fields:
title
- Quest titledescription
- Quest description (optional)category
- Quest categorypriority
- Quest priorityGet comprehensive player profile and statistics.
Query Parameters:
include_quests
- Include detailed quest information (true/false)include_stats
- Include calculated statistics (true/false, default true)Available Players:
alex
- Level 15, experienced playerjordan
- Level 8, intermediate playersam
- Level 22, veteran playerdemo
- Level 1, new playerGet player leaderboard with rankings.
Query Parameters:
sort_by
- Sort field (level, xp, streak, activity)order
- Sort order (asc, desc)limit
- Maximum results (1-50)Features:
Get all quest categories with optional statistics.
Query Parameters:
search
- Search categories by name, description, or tagsinclude_stats
- Include quest statistics (true/false)sort_by
- Sort field (name, popularity, xp_multiplier)Available Categories:
Get detailed category information with tips and suggestions.
Features:
All /api/*
endpoints require authentication via API key.
Demo API Keys:
demo_key_12345
- Primary demo keytest_key_67890
- Secondary test keystudent_key_abcde
- Student practice keydev_key_quickstart
- Quick development keyAuthentication Methods:
curl -H "X-API-Key: demo_key_12345" http://localhost:3000/api/quests
curl "http://localhost:3000/api/quests?api_key=demo_key_12345"
X-RateLimit-*
headers in responsesOpen test.html
in your browser for a comprehensive testing interface featuring:
Basic curl commands:
# Get server info
curl http://localhost:3000/
# Test authentication
curl -H "X-API-Key: demo_key_12345" http://localhost:3000/api/quests
# Get specific quest
curl "http://localhost:3000/api/quests/1?api_key=demo_key_12345"
# Complete a quest
curl -X POST -H "X-API-Key: demo_key_12345" \
http://localhost:3000/api/quests/1/complete
# Get player profile
curl "http://localhost:3000/api/players/alex?api_key=demo_key_12345"
# Get categories with stats
curl "http://localhost:3000/api/categories?include_stats=true&api_key=demo_key_12345"
# Start server
npm start
# Development with auto-reload
npm run dev
# Test endpoints
npm run test
# Health check
npm run health
tags
, difficulty
, or estimated_time
/api/quests/:id
test.html
/health
endpoint shows server status/api/stats
shows performance metricstest.html
shows real-time request/response dataBy completing this activity, you'll have hands-on experience with:
Ready to build amazing APIs? Start your server and open test.html
to begin testing! ๐