Skip to content

AbdullahASCS/cd0037-API-Development-and-Documentation-project

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Development and Documentation Final Project

Trivia App

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:

  1. 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.
  2. Delete questions.
  3. Add questions and require that they include question and answer text.
  4. Search for questions based on a text query string.
  5. Play the quiz game, randomizing either all questions or within a specific category.

Base Path

localhost:5000


API Endpoints

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 of id: 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"
}

Error Codes

400

{
"status": "error",  
"errorCode": "400",  
"message": "Bad request"
}

404

{
"status": " error",  
"errorCode": "404",  
"message": "The requested resource was not found"
}

422

{
"status": "error",  
"errorCode": "422",  
"message": "The request cannot be processed due to an unprocessable entity"
}

500

{
"status": "error",  
"errorCode": "500",  
"message": "Internal server error"
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 48.5%
  • Python 43.7%
  • CSS 6.5%
  • HTML 1.3%