Giter Club home page Giter Club logo

udacity-02_trivia_api's Introduction

Trivia API

Objective Overview

Trivia API is RESTful API basic example supported by Udacity and Egypt FWD Trivia API is mainly full stack webpage that manage the trivia app and play the game. user can play quizzes either generally or filered by a category (Science,Arts,Sports,History,Geography and Entertainment) each question has a difficulty level.

Techinical Overview

Trivia API performs basic CRUD operations on Postgresql database,handles common errors such as 404 and 422. Trivia API also uses CORS and configures Access-Control-Allow-Methods to use meothods:GET,POST and DELETE.

Categories

Get all available categories

Url

/categories

Method

Get

Response

{
  "categories": {
    "1": "Science",
    "2": "Art",
    "3": "Geography",
    "4": "History",
    "5": "Entertainment",
    "6": "Sports"
  }
}

Questions

Get questions including pagination (every 10 questions) and returns a list of questions, number of total questions, current category, categories.

Url

/questions

Method

Get

Response

{
  "categories": {
    "1": "Science",
    "2": "Art",
    "3": "Geography",
    "4": "History",
    "5": "Entertainment",
    "6": "Sports"
  },
  "current_category": [
    4,
    6,
    3,
    1,
    4,
    1,
    4,
    1,
    5,
    3
  ],
  "page": 1,
  "questions": [
    {
      "answer": "Scarab",
      "category": 4,
      "difficulty": 4,
      "id": 23,
      "question": "Which dung beetle was worshipped by the ancient Egyptians?"
    },
    {
      "answer": "Uruguay",
      "category": 6,
      "difficulty": 4,
      "id": 11,
      "question": "Which country won the first ever soccer World Cup in 1930?"
    },
    {
      "answer": "answer new q 20",
      "category": 3,
      "difficulty": 3,
      "id": 50,
      "question": "new question 20"
    },
    {
      "answer": "The Liver",
      "category": 1,
      "difficulty": 4,
      "id": 20,
      "question": "What is the heaviest organ in the human body?"
    },
    {
      "answer": "answer new q 12",
      "category": 4,
      "difficulty": 4,
      "id": 44,
      "question": "new question 12"
    },
    {
      "answer": "new answer 9",
      "category": 1,
      "difficulty": 3,
      "id": 45,
      "question": "new q 9"
    },
    {
      "answer": "George Washington Carver",
      "category": 4,
      "difficulty": 2,
      "id": 12,
      "question": "Who invented Peanut Butter?"
    },
    {
      "answer": "Blood",
      "category": 1,
      "difficulty": 4,
      "id": 22,
      "question": "Hematology is a branch of medicine involving the study of what?"
    },
    {
      "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": "Agra",
      "category": 3,
      "difficulty": 2,
      "id": 15,
      "question": "The Taj Mahal is located in which Indian city?"
    }
  ],
  "total_questions": 22
}

Get questions based on category where is the id of required category.

Url

/categories/<id>/questions

Method

Get

Response

{
  "categories": {
    "1": "Science",
    "2": "Art",
    "3": "Geography",
    "4": "History",
    "5": "Entertainment",
    "6": "Sports"
  },
  "current_category": [
    4,
    4,
    4,
    4
  ],
  "page": 1,
  "questions": [
    {
      "answer": "George Washington Carver",
      "category": 4,
      "difficulty": 2,
      "id": 12,
      "question": "Who invented Peanut Butter?"
    },
    {
      "answer": "Scarab",
      "category": 4,
      "difficulty": 4,
      "id": 23,
      "question": "Which dung beetle was worshipped by the ancient Egyptians?"
    },
    {
      "answer": "new answer 9",
      "category": 4,
      "difficulty": 3,
      "id": 42,
      "question": "new q 9"
    },
    {
      "answer": "answer new q 12",
      "category": 4,
      "difficulty": 4,
      "id": 44,
      "question": "new question 12"
    }
  ],
  "total_questions": 4
}

Delete question where is the id of required question.

Url

/questions/<id>

Method

Delete

Response:

{
  "message": "Deleted",
  "success": true
}

Post a new question,which has a question and answer text,category, and difficulty.

Url

/questions

Method

Post

Data:

to use this endpoint your request should include json data as below

{
      "answer": "Scarab",
      "category": 4,
      "difficulty": 4,
      "id": 23,
      "question": "Which dung beetle was worshipped by the ancient Egyptians?"
    }

Response

{
  "message": "Inserted",
  "success": true
}

Get questions based on a search term (case-insensative).returns any questions for whom the search term is a substring of the question.

Url

/questions/search

Method

Post

Data

to use this endpoint your request should include json data as below

{
	"searchTerm":"which"
}

Response

{
  "categories": {
    "1": "Science",
    "2": "Art",
    "3": "Geography",
    "4": "History",
    "5": "Entertainment",
    "6": "Sports"
  },
  "current_category": [
    6,
    3,
    3,
    2,
    4
  ],
  "questions": [
    {
      "answer": "Uruguay",
      "category": 6,
      "difficulty": 4,
      "id": 11,
      "question": "Which country won the first ever soccer World Cup in 1930?"
    },
    {
      "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–initials M C was a creator of optical illusions?"
    },
    {
      "answer": "Scarab",
      "category": 4,
      "difficulty": 4,
      "id": 23,
      "question": "Which dung beetle was worshipped by the ancient Egyptians?"
    }
  ],
  "searchTerm": "which"
}

Quizzes

Get questions to play the quiz.returns a random questions within the given category,if provided, and that is not one of the previous questions.data must contains category (for all catgeories use category 0 ) and previous question ids.

Url

/quizzes

Method

Post

Data

to use this endpoint your request should include json data as below

{
	"previous_questions":[7],
	"quiz_category":{"id":0}
}

Response

{
  "question": {
    "answer": "Mona Lisa",
    "category": 1,
    "difficulty": 3,
    "id": 17,
    "question": "La Giaconda is better known as what?"
  }
}

Errors

for abnormal operations you will receive a descriptive error messages

Unprocessable Request

 {
        "success": False, 
        "error": 422,
        "message": "Unprocessable"
        }

Not Found Resource

        {
        "success": False, 
        "error": 404,
        "message": "Not found"
        }

Refrences

https://stackoverflow.com/ https://www.sqlalchemy.org/ https://code.visualstudio.com/docs https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-ix-pagination

udacity-02_trivia_api's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.