Student starter code (30% baseline)
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!
Welcome to your advanced Express.js API project! This template helps you build a production-ready REST API for a gamified quest management system with authentication, rate limiting, and comprehensive error handling.
By completing this activity, you will:
IMPORTANT: This template includes WORKING API ENDPOINTS! Test them immediately:
npm install
npm start
70% of the API is implemented for you:
activity-11-quest-api/
โโโ server.js # Main Express server (middleware setup)
โโโ routes/
โ โโโ quests.js # Quest CRUD endpoints
โ โโโ players.js # Player profiles and leaderboards
โ โโโ categories.js # Quest categories
โโโ middleware/ # Authentication & logging (TODO section)
โโโ test.html # Interactive API testing interface
โโโ package.json # Dependencies and npm scripts
โโโ README.md # This file
Complete the POST /api/quests/:id/complete endpoint to mark quests as completed and calculate XP rewards.
API Endpoint: POST /api/quests/:id/complete
Success Criteria:
Hint: Look at the enrichQuestData() function in routes/quests.js for the XP calculation pattern.
Implement the POST /api/quests endpoint to create new quests with validation.
API Endpoint: POST /api/quests
Required Fields:
title (string, required)description (string, optional)category (string, required - work/health/personal/learning/creative)priority (string, required - low/medium/high/critical)deadline (ISO date string, optional)Success Criteria:
Create custom authentication middleware in the middleware/ folder to verify API keys.
File to create: middleware/auth.js
Requirements:
X-API-Key header or api_key query parameterreq.user for valid keys/api/* routesSuccess Criteria:
/api/* endpoints require valid API keyEnhance the GET /api/quests endpoint with advanced filtering capabilities.
Features to implement:
Success Criteria:
/api/quests?tags=work,urgent&difficulty=hard returns filtered results/api/quests?deadline_before=2024-01-20&status=pending works correctlyAdd calculated statistics to the player profile endpoint.
Endpoint to enhance: GET /api/players/:username
Statistics to add:
Success Criteria:
stats objectGet all quests with filtering and sorting options.
Query Parameters:
status - Filter by status (pending, in_progress, completed)priority - Filter by priority (low, medium, high, critical)category - Filter by category (work, health, personal, learning, creative)sort_by - Sort field (created_at, priority, deadline, xp_reward)order - Sort order (asc, desc)limit - Maximum results (default: 50)Example:
curl "http://localhost:3000/api/quests?status=pending&priority=high&api_key=demo_key_12345"
Get detailed information about a specific quest with enriched data.
Features included:
Mark a quest as completed and calculate XP rewards.
Create a new quest with custom parameters.
Get comprehensive player profile and statistics.
Available Players:
alex - Level 15, experienced playerjordan - Level 8, intermediate playersam - Level 22, veteran playerdemo - Level 1, new playerQuery Parameters:
include_quests - Include detailed quest array (true/false)include_stats - Include calculated statistics (true/false, default: true)Get player leaderboard with rankings and activity scores.
Query Parameters:
sort_by - Sort field (level, xp, streak, activity)order - Sort order (asc, desc)limit - Maximum results (default: 10)Get all quest categories with optional statistics.
Available Categories:
Query Parameters:
search - Search by name, description, or tagsinclude_stats - Include quest statistics (true/false)sort_by - Sort field (name, popularity, xp_multiplier)Get detailed category information with tips and suggestions.
All /api/* endpoints require authentication via API key.
Demo API Keys (use for testing):
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"
Security Features:
Open test.html in your browser for a comprehensive testing interface:
Quick test commands:
# 1. Get all quests (test basic endpoint)
curl "http://localhost:3000/api/quests?api_key=demo_key_12345"
# 2. Get specific quest (test parameterized route)
curl "http://localhost:3000/api/quests/1?api_key=demo_key_12345"
# 3. Get player profile (test data enrichment)
curl "http://localhost:3000/api/players/alex?api_key=demo_key_12345"
# 4. Filter quests by priority (test query parameters)
curl "http://localhost:3000/api/quests?priority=high&api_key=demo_key_12345"
# 5. Get categories with stats
curl "http://localhost:3000/api/categories?include_stats=true&api_key=demo_key_12345"
# 6. Test authentication (should fail without API key)
curl http://localhost:3000/api/quests
Ready to take your API skills further? Try these bonus features:
/api/quests/:id to update quest details/api/quests/:id with proper error handlingpage and per_page parameters/api/players to register new playersYour project is complete when:
Once you complete this project, you'll have:
This foundation will serve you well in building real-world APIs, microservices, and full-stack applications!
Need Help?
Common Issues:
Happy coding!