The following is an API created for a quiz game on different topics.
The main objective of this project is to provide users with a platform where they can have fun and learn with interesting questions and facts.
- User authentication using Passport
- Creation and management of questions
- Management of answers to questions
To set up the local environment, follow these instructions in order:
# 1. Clone the repository from GitHub
git clone https://github.com/LZJorge/Quiz-API.git
# 2. Enter to generated folder
cd Quiz-API
# 3. Install dependencies
npm install
# 4. Compile TypeScript code
npm run build
# 5. Start the server
npm start
You can run api tests with
# Use this to test api
npm test
The API is used through HTTP requests to the available endpoints.
Below is a table of the available endpoints in this API.
Method | URL | Description | Request body |
---|---|---|---|
GET | /question | Gives a random question (or active a question) | N/A |
GET | /question/:category | Gives a random question filtered by especific category (updates active a question) | param: category |
GET | /category/get | Gives list of all availables categories | N/A |
POST, PUT, PATCH | /question | Send answer (to user active question) | answer |
POST | /auth/login | Authenticate user | username , password |
POST | /user/create | Register user | username , password , passwordConfirm |
PUT, PATCH | /user/update/password | Update User Password | password , newPassword , newPasswordConfirm |
PUT, PATCH | /user/update/avatar | Update User Avatar | newAvatar |
DELETE | /user/delete | Deletes user | userID |
GET | /user/getLeaderboard | Gives 10 user with highest score | N/A |
GET | /user/current | Gives user session data | N/A |
GET | /user/logout | Destroys current session | N/A |
GET | /avatars/get | Get all public avatars | N/A |
POST {{API}}/user/create
content-type: application/json
{
"username": "sample",
"password": "12345678",
"passwordConfirm": "12345678"
}
POST {{API}}/auth/login
content-type: application/json
{
"username": "sample",
"password": "12345678"
}
PUT {{API}}/question
content-type: application/json
{
"answer": "Brasil"
}
{
"code": "success",
"user": {
"id": "uuid147f-bc20-4cd4-99f9-a9ba787db693",
"username": "JohnDoe",
"avatar": "avatars/avatar-00.svg",
"score": 0,
"totalQuestions": 0,
"successResponses": 0,
"createdAt": "2023-07-19T13:29:19.925Z"
}
}
{
"id": 34,
"question": "¿Cuál es el equipo de fútbol con más títulos de la Copa Libertadores de América?",
"correctAnswer": "Club Atlético Independiente",
"options": [
"Club Atlético Independiente",
"Boca Juniors",
"River Plate",
"São Paulo FC"
],
"points": 20,
"difficulty": "Difícil",
"Category": {
"name": "Deportes"
}
}
Finished
- Improvement of documentation
- Add support for other database engines
Please read the following information carefully before using this API:
- Authentication is required for certain API endpoints.
- Please note that for the beta version, the questions have been generated with ChatGPT, so there may be errors or inconsistencies in them.
Created by @LZJorge - feel free to contact me!