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.
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.
localhost:5000
GET '/categories'
- Fetches a dictionary of categories in which the keys are the ids and the value is the corresponding string of the category
- Request Arguments: None
- Returns: An object with a single key,
categories
, that contains an object ofid: category_string
key: value pairs.
{
"categories": {
"1": "Science",
"2": "Art",
"3": "Geography",
"4": "History",
"5": "Entertainment",
"6": "Sports"
}
}
GET '/questions?page=${integer}'
- Fetches a paginated set of questions, a total number of questions, all categories and current category string.
- Request Arguments:
page
- integer - Returns: An object with 10 paginated questions, total questions, object including all categories, and current category string
{
"questions": [
{
"id": 1,
"question": "This is a question",
"answer": "This is an answer",
"difficulty": 5,
"category": 2
}
],
"totalQuestions": 100,
"categories": {
"1": "Science",
"2": "Art",
"3": "Geography",
"4": "History",
"5": "Entertainment",
"6": "Sports"
},
"currentCategory": "History"
}
GET '/categories/${id}/questions'
- Fetches questions for a cateogry specified by id request argument
- Request Arguments:
id
- integer - Returns: An object with questions for the specified category, total questions, and current category string
{
"questions": [
{
"id": 1,
"question": "This is a question",
"answer": "This is an answer",
"difficulty": 5,
"category": 4
}
],
"totalQuestions": 100,
"currentCategory": "History"
}
DELETE '/questions/${id}'
- Deletes a specified question using the id of the question
- Request Arguments:
id
- integer - Returns: the appropriate HTTP status code.
POST '/quiz'
- Sends a post request in order to get the next question
- Request Body:
{
"previous_questions": [1, 4, 20, 15],
"quiz_category": "current category"
}
- Returns: a single new question object
{
"question": {
"id": 1,
"question": "This is a question",
"answer": "This is an answer",
"difficulty": 5,
"category": 4
}
}
POST '/questions'
- Sends a post request in order to add a new question
- Request Body:
{
"question": "Heres a new question string",
"answer": "Heres a new answer string",
"difficulty": 1,
"category": 3
}
- Returns: Does not return any new data
POST '/questions/search'
- Sends a post request in order to search for a specific question by search term
- Request Body:
{
"searchTerm": "this is the term the user is looking for"
}
- Returns: any array of questions, a number of totalQuestions that met the search term and the current category string
{
"questions": [
{
"id": 1,
"question": "This is a question",
"answer": "This is an answer",
"difficulty": 5,
"category": 5
}
],
"totalQuestions": 100,
"currentCategory": "Entertainment"
}
{
"status": "error",
"errorCode": "400",
"message": "Bad request"
}
{
"status": " error",
"errorCode": "404",
"message": "The requested resource was not found"
}
{
"status": "error",
"errorCode": "422",
"message": "The request cannot be processed due to an unprocessable entity"
}
{
"status": "error",
"errorCode": "500",
"message": "Internal server error"
}