This application can:
- Display questions - both all questions and by category. Questions show the question, category and difficulty rating by default and can show/hide the answer.
- Delete questions.
- Add questions and require that they include question and answer text.
- Search for questions based on a text query string.
- Play the quiz game, randomizing either all questions or within a specific category.
You need to install Python3.7, virtual environment, pip and node on your local machine to run this project.
First, create virtual environment and activate it.
From the backend folder run pip install -r requirements.txt
. All required packages are included in the requirements file.
To run the application run the following commands:
export FLASK_APP=flaskr
export FLASK_ENV=development
flask run
These commands put the application in development and directs our app to use the __init__.py
file in our flaskr folder. Working in development mode shows an interactive debugger in the console and restarts the server whenever changes are made. If running locally on Windows, look for the commands in the Flask documentation.
The app is run on http://127.0.0.1:5000/
by default and is a proxy in the forntend configuration.
From the frontend folder, run the following commands to start the client:
npm install // only once to install dependencies
npm start
By default, the frontend will run on localhost:3000.
In order to run tests, navigate to the backend folder and run the following commands:
dropdb trivia
createdb trivia
psql trivia < trivia.psql
python flaskr.py
The first time you run the tests, omit the dropdb command.
All tests are kept in that file and should be maintained as updates are made to app functionality.
- Base URL: At present this app can only be run locally and is not hosted as a base URL. The backend app is hosted at the default,
http://127.0.0.1:5000/
, which is set as a proxy in the frontend configuration. - Authentication: This version of the application does not require authentication or API keys.
Errors are returned as JSON objects in the following format:
{
"success": False,
"error": 400,
"message": "bad request"
}
The API will return three error types when requests fail:
- 400: Bad Request
- 404: Resource Not Found
- 422: Not Processable
- General:
- Returns a list of question objects, success value, total number of questions, a list of categogry types object and current category
- Results are paginated in groups of 10. Include a request argument to choose page number, starting from 1.
- Sample:
curl http://127.0.0.1:5000/questions
"categories": [
{
"id": 1,
"type": "Science"
},
{
"id": 2,
"type": "Art"
},
{
"id": 3,
"type": "Geography"
},
{
"id": 4,
"type": "History"
},
{
"id": 5,
"type": "Entertainment"
},
{
"id": 6,
"type": "Sports"
}
],
"current_category": "History",
"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": "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?"
},
{
"answer": "Agra",
"category": 3,
"difficulty": 2,
"id": 15,
"question": "The Taj Mahal is located in which Indian city?"
}
],
"success": true,
"total_questions": 38
}
- General:
- Returns an object of category objects and success value
- Sample:
curl http://127.0.0.1:5000/categories
{
"categories": {
"1": "Science",
"2": "Art",
"3": "Geography",
"4": "History",
"5": "Entertainment",
"6": "Sports"
},
"success": true
}
- General:
- Returns a list of questions objects, success value, current category type and total number of questions.
- Results are paginated in groups of 10. Include a request argument to choose page number, starting from 1.
- Sample:
curl http://127.0.0.1:5000/categories/1/questions
{
"current_category": "Science",
"questions": [
{
"answer": "The Liver",
"category": 1,
"difficulty": 4,
"id": 20,
"question": "What is the heaviest organ in the human body?"
},
{
"answer": "Alexander Fleming",
"category": 1,
"difficulty": 3,
"id": 21,
"question": "Who discovered penicillin?"
},
{
"answer": "Blood",
"category": 1,
"difficulty": 4,
"id": 22,
"question": "Hematology is a branch of medicine involving the study of what?"
},
{
"answer": "Nobody",
"category": 1,
"difficulty": 5,
"id": 27,
"question": "Who Cares?"
},
{
"answer": "321",
"category": 1,
"difficulty": 3,
"id": 28,
"question": "213"
},
{
"answer": "nobody",
"category": 1,
"difficulty": 3,
"id": 41,
"question": "whocares2"
},
{
"answer": "test1",
"category": 1,
"difficulty": 1,
"id": 72,
"question": "test1"
},
{
"answer": "test1",
"category": 1,
"difficulty": 1,
"id": 74,
"question": "test1"
},
{
"answer": "test13",
"category": 1,
"difficulty": 1,
"id": 80,
"question": "test13"
},
{
"answer": "test12",
"category": 1,
"difficulty": 1,
"id": 81,
"question": "test12"
}
],
"success": true,
"total_questions": 12
}
- General:
- Deletes the question of the given ID if it exists. Returns the id of the deleted question, success value, total number of questions, and question list based on current page number to update the frontend.
- Results are paginated in groups of 10. Include a request argument to choose page number, starting from 1.
curl -X DELETE http://127.0.0.1:5000/questions/20
{
"deleted": 20,
"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": "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?"
},
{
"answer": "Agra",
"category": 3,
"difficulty": 2,
"id": 15,
"question": "The Taj Mahal is located in which Indian city?"
}
],
"success": true,
"total_questions": 37
}
- General:
- Creates a new question using the submitted question, answer, difficulty and category. Returns the id of the created book, success value, total number of questions, and question list based on current page number to update the frontend.
- Results are paginated in groups of 10. Include a request argument to choose page number, starting from 1.
curl http://127.0.0.1:5000/questions -X POST -H "Content-Type: application/json" -d '{"question": "who is the owner of tesla", "answer": "Elon Musk", "difficulty": 1, "category": 1}'
{
"created": 89,
"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": "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?"
},
{
"answer": "Agra",
"category": 3,
"difficulty": 2,
"id": 15,
"question": "The Taj Mahal is located in which Indian city?"
}
],
"success": true,
"total_questions": 40
}
- General:
- Gets questions based on a search term. Returns any questions for who the search term is a substring of the questions, success value, current category and total number of questions.
- Results are paginated in groups of 8. Include a request argument to choose page number, starting from 1.
curl --request POST --url http://127.0.0.1:5000/questions/search --header 'Content-Type: application/json' --data '{"searchTerm": "title"}'
{
"current_category": "History",
"questions": [
{
"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?"
}
],
"success": true,
"total_questions": 1
}
- General:
- Gets questions to play the quiz. Takes category and previous question parameters. Returns a random question within the given category (if provided), and that is not one of the previous questions.
- Sample:
curl --request POST --url http://127.0.0.1:5000/quizzes --header 'Content-Type: application/json' --data '{ "previous_questions": [], "quiz_category": {"type": "Science", id": 1}}'
{
"question": {
"answer": "Elon Musk",
"category": 1,
"difficulty": 1,
"id": 89,
"question": "who is the owner of tesla"
},
"success": true
}
Abdulaziz Sukhrobjonov - LinkedIn | GitHub
Diyorbek Azimqulov - LinkedIn | GitHub
The Treasure Library
is a public domain work, dedicated using
CC0 1.0. Feel free to do
whatever you want with it.