A project for Udacity"s Full Stack Web Developer Nanodegree Program, Part 2: API Development and Documentation.
Check out the original repo for more information on the project, or see the rest of the projects completed for the nanodegree.
- Flask
- SQLAlchemy
- React
- The app is run locally, and is not hosted as a base URL. The backend is hosted at the default
http:127.0.0.1:5000/
. - No authentication or API keys are required
Errors are returned in the following format:
{
"code": 404,
"description": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"name": "Not Found"
}
The following types of errors are returned, depending on the request:
- 404: Not found
- 405: Method not allowed
- 422: Unprocesseable request
Get a list of the categories questions can belong in.
- Request:
curl -X GET http:127.0.0.1:5000/categories
- Response:
{ "categories": { "1": "Science", "2": "Art", "3": "Geography", "4": "History", "5": "Entertainment", "6": "Sports" } }
Get a list of questions.
page
(integer, optional): Questions are split into pages of 10. Set a value to return the specified page, or the first page if left out.
- Request:
curl -X GET http:127.0.0.1:5000/questions?page=1
- Response:
{ "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?" }, ... ], "total_questions": 19 }
Delete the specified question.
- Request:
curl -X DELETE http:127.0.0.1:5000/questions/1
- Response: An empty json object will be returned if successful.
SearchTerm
(string, required): Term to search for. The search will be case-insensitive.
{
"searchTerm": "foo"
}
question
(string, required): The question to addanswer
(string, required): Answer to the question being addedcategory
(integer, required): Category the question belongs todifficulty
(integer, required): Difficulty of the question
{
"question": "What is the largest mammal?",
"answer": "Blue whale",
"category": 1,
"difficulty": 2
}
page
(integer, optional): Questions are split into pages of 10. Set a value to return the specified page, or the first page if left out.
- Request:
curl -X POST http://127.0.0.1:5000/questions -H "Content-Type: application/json" -d '{"searchTerm":"The"}'
- Response:
{ "categories": { "1": "Science", "2": "Art", "3": "Geography", "4": "History", "5": "Entertainment", "6": "Sports" }, "current_category": null, "questions": [ { "answer": "Maya Angelou", "category": 4, "difficulty": 2, "id": 5, "question": "Whose autobiography is entitled 'I Know Why the Caged Bird Sings'?" }, ... ], "total_questions": 11 }
- Request:
curl -X POST http://127.0.0.1:5000/questions -H "Content-Type: application/json" -d '{"question": "What is the largest mammal?", "answer": "Blue whale", "category": 1, "difficulty": 2}'
- Response:
{ "categories": { "1": "Science", "2": "Art", "3": "Geography", "4": "History", "5": "Entertainment", "6": "Sports" }, "current_category": null, "questions": [ { "answer": "Maya Angelou", "category": 4, "difficulty": 2, "id": 5, "question": "Whose autobiography is entitled 'I Know Why the Caged Bird Sings'?" }, ... ], "total_questions": 11 }
Get a list of questions based on the specified category.
page
(integer, optional): Questions are split into pages of 10. Set a value to return the specified page, or the first page if left out.
- Request:
curl -X GET http://127.0.0.1:5000/categories/1/questions
- Response:
{ "categories": { "1": "Science", "2": "Art", "3": "Geography", "4": "History", "5": "Entertainment", "6": "Sports" }, "current_category": "Science", "questions": [ { "answer": "The Liver", "category": 1, "difficulty": 4, "id": 20, "question": "What is the heaviest organ in the human body?" }, ... ], "total_questions": 3 }
Play the quiz. Returns a single random question belonging to the category.
quiz_category
(string, required): The category to pull questions from.previous_questions
(list of int, required): IDs to remove from pool of possible questions
{
"quiz_category": { "id": "2", "type": "Art" },
"previous_questions": [16, 17, 18]
}
- Request:
curl -X POST http://127.0.0.1:5000/quizzes -H "Content-Type: application/json" -d '{"quiz_category": {"id": "2", "type": "Art"}, "previous_questions": [16, 17, 18]}'
- Response:
{ "question": { "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?" } }