Udacity is invested in creating bonding experiences for its employees and students. A bunch of team members got the idea to hold trivia on a regular basis and created a webpage to manage the trivia app and play the game, but their API experience is limited and still needs to be built out.
That's where you come in! Help them finish the trivia app so they can start holding trivia and seeing who's the most knowledgeable of the bunch. The application must:
- Display questions - both all questions and by category. Questions should 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.
Completing this trivia app will give you the ability to structure plan, implement, and test an API - skills essential for enabling your future applications to communicate with others.
There are TODO
comments throughout project. Start by reading the READMEs in:
We recommend following the instructions in those files in order. This order will look familiar from our prior work in the course.
Fork the project repository and Clone your forked repository to your machine. Work on the project locally and make sure to push all your changes to the remote repository before submitting the link to your repository in the Classroom.
We started the full stack application for you. It is desiged with some key functional areas:
The ./backend
directory contains a partially completed Flask and SQLAlchemy server. You will work primarily in app.py to define your endpoints and can reference models.py for DB and SQLAlchemy setup.
The ./frontend
directory contains a complete React frontend to consume the data from the Flask server. You will need to update the endpoints after you define them in the backend. Those areas are marked with TODO and can be searched for expediency.
Pay special attention to what data the frontend is expecting from each API response to help guide how you format your API.
View the README.md within ./frontend for more details.
Please follow the following instructions in order to run the project:
Inside the backend folder:
- Please add your postgres database path at the flaskr/init.py file
pip install -r requirements.txt
psql trivia < trivia.psql
export FLASK_APP=flaskr
export FLASK_ENV=development
flask run
Inside the frontend folder:
npm install
npm start
Endpoint | Method | Parameters | Behavior |
---|---|---|---|
/questions | GET | - | Returns list of questions |
/categories | GET | - | Returns list of categories |
/questions/ | DEL | question_id | Deletes a question |
/questions | POST | - | Creates a new question |
/categories//questions | GET | category_id | List of questions from certain category |
/quizzes | POST | previous_questions , quiz_category | Gives the question to the user to play. |
/questions
{
"categories": {
"1": "Science",
"2": "Art",
"3": "Geography",
"4": "History",
"5": "Entertainment",
"6": "Sports"
},
"current_category": null,
"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?"
},
{
"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?"
},
{
"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?"
}
],
"success": true,
"total_questions": 43
}
/categories
{
"categories": {
"1": "Science",
"2": "Art",
"3": "Geography",
"4": "History",
"5": "Entertainment",
"6": "Sports"
},
"success": true
}
/categories/6/questions
{
"current_category": 6,
"questions": [
{
"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?"
}
],
"total_questions": 2
}
/questions/6 (DEL)
{
"deleted_question": 6,
"success": true
}
/questions (POST)
{
"success": true
}
/quizzes (POST -> Category ALL)
{
"answer": "Uruguay",
"category": "6",
"difficulty": 4,
"id": 11,
"question": "Which country won the first ever soccer World Cup in 1930?"
}