Trivia API is a quiz app! Expand your knowledge by going through all questions, or specific questions by category. Feel like you have a good question you don't see already, you can add it! Want a little challenge, then go to the "play" mode and see how many points can you get out of five!
Happy trivia-ing!
Navigate to the project directory. Then create a python virtual environment. Steps to setup and activate your virtual environment is in the Python Docs on this link.
Once the python virtual environment has been activated, install the requirements by running the following command
pip install -r requirements.txt
Navigate to the frontend directory. Now run the following commands to start the frontend server.
npm install
npm start
Now the frontend is hosted on http://localhost:3000 !
Navigate to the backend directory. Now run the following commands to start the backend server.
export FLASK_APP=flaskr
export FLASK_ENV=development
flask run
- Modify the postgres username and password in the database_path variable in models.py
- Modify the postgres username and password in the self.database_path variable in testing_path.py
- Create a database with the name trivia_test
- Run
psql -d trivia_test -u <username> -a -f trivia.psql
This add sample questions and categories to the test database.
Get a list of questions paginated in groups of ten, categories, and total number of questions ignoring the pagination. Current category that is returned is always None (null).
curl -X GET http://localhost:5000/questions
curl -X GET http://localhost:5000/questions?page=2
{
"categories": {
"1": "Science",
"2": "Art",
"3": "Geography",
"4": "History",
"5": "Entertainment",
"6": "Sports"
},
"current_category": null,
"questions": [
{
"answer": "Apollo 13",
"category": 5,
"difficulty": 4,
"id": 2,
"question": "What movie earned Tom Hanks his third straight Oscar nomination, in 1996?"
},
{
"answer": "Tom Cruise",
"category": 5,
"difficulty": 4,
"id": 4,
"question": "What actor did author Anne Rice first denounce, then praise in the role of her beloved Lestat?"
},
{
"answer": "Maya Angelou",
"category": 4,
"difficulty": 2,
"id": 5,
"question": "Whose autobiography is entitled 'I Know Why the Caged Bird Sings'?"
},
{
"answer": "Edward Scissorhands",
"category": 5,
"difficulty": 3,
"id": 6,
"question": "What was the title of the 1990 fantasy directed by Tim Burton about a young man with multi-bladed appendages?"
},
{
"answer": "Muhammad Ali",
"category": 4,
"difficulty": 1,
"id": 9,
"question": "What boxer's original name is Cassius Clay?"
},
{
"answer": "Brazil",
"category": 6,
"difficulty": 3,
"id": 10,
"question": "Which is the only team to play in every soccer World Cup tournament?"
},
{
"answer": "Uruguay",
"category": 6,
"difficulty": 4,
"id": 11,
"question": "Which country won the first ever soccer World Cup in 1930?"
},
{
"answer": "George Washington Carver",
"category": 4,
"difficulty": 2,
"id": 12,
"question": "Who invented Peanut Butter?"
},
{
"answer": "Lake Victoria",
"category": 3,
"difficulty": 2,
"id": 13,
"question": "What is the largest lake in Africa?"
},
{
"answer": "The Palace of Versailles",
"category": 3,
"difficulty": 3,
"id": 14,
"question": "In which royal palace would you find the Hall of Mirrors?"
}
],
"total_questions": 19
}
Get a list of questions paginated in groups of ten that match the passed search query. Also get the total number of matches. Current category that is returned is always None (null).
Note: "searchTerm" must be passed in the body. If not, a 400 error code response will be returned.
curl -X POST http://localhost:5000/questions/search -d '{"searchTerm": "Lestat"}' -H "Content-Type: application/json"
curl -X POST http://localhost:5000/questions/search?page=3 -d '{"searchTerm": "Steve"}' -H "Content-Type: application/json"
{
"current_category": null,
"questions": [
{
"answer": "Tom Cruise",
"category": 5,
"difficulty": 4,
"id": 4,
"question": "What actor did author Anne Rice first denounce, then praise in the role of her beloved Lestat?"
}
],
"total_questions": 1
}
Get a list of questions paginated in groups of ten that are from the category passed in the path. Also get the total number of questions fitting this constraint. Current category that is returned is always None (null).
curl -X GET http://localhost:5000/categories/2/questions curl -X GET http://localhost:5000/categories/2/questions?page=2
{
"current_category": null,
"questions": [
{
"answer": "Escher",
"category": 2,
"difficulty": 1,
"id": 16,
"question": "Which Dutch graphic artist\u2013initials M C was a creator of optical illusions?"
},
{
"answer": "Mona Lisa",
"category": 2,
"difficulty": 3,
"id": 17,
"question": "La Giaconda is better known as what?"
},
{
"answer": "One",
"category": 2,
"difficulty": 4,
"id": 18,
"question": "How many paintings did Van Gogh sell in his lifetime?"
},
{
"answer": "Jackson Pollock",
"category": 2,
"difficulty": 2,
"id": 19,
"question": "Which American artist was a pioneer of Abstract Expressionism, and a leading exponent of action painting?"
}
],
"total_questions": 4
}
Get a question that's from the category passed in the body of the request. This question will also be different from the ones passed in the body. This ensures no question is repeated in any round.
Note: "previous_questions" and "quiz_category" must be passed in the body. If not, a 400 error code response will be returned.
curl -X POST http://localhost:5000/quizzes -H 'Content-Type: application/json' -d '{"previous_questions": [2, 3], "quiz_category": {"id": 2, "type": "Art"}}'
curl -X POST http://localhost:5000/quizzes -H 'Content-Type: application/json' -d '{"previous_questions": [], "quiz_category": {"id": 1, "type": "Science"}}'
{
"question": {
"answer": "Mona Lisa",
"category": 2,
"difficulty": 3,
"id": 17,
"question": "La Giaconda is better known as what?"
}
}
Get a list of categories along with the number of categories
curl -X GET http://localhost:5000/categories
{
"categories": {
"1": "Science",
"2": "Art",
"3": "Geography",
"4": "History",
"5": "Entertainment",
"6": "Sports"
},
"count_categories": 6
}
Add a question. The added question is then returned in the response.
Note: "question", "answer", "category", and "difficulty" must be passed in the body. If not, a 400 error code response will be returned.
curl -X POST http://localhost:5000/questions -H 'Content-Type: application/json' -d '{"question": "QUESTION", "answer": "ANSWER", "category": 2, "difficulty": 5}'
{
"question": {
"answer": "ANSWER",
"category": 2,
"difficulty": 5,
"id": 26,
"question": "QUESTION"
}
}
Deletes a question. The deleted question is then returned in the response.
curl -X DELETE http://localhost:5000/questions/26
{
"question": {
"answer": "ANSWER",
"category": 2,
"difficulty": 5,
"id": 26,
"question": "QUESTION"
}
}