URL : This app will run locally as it is not hosted on a URL yet. The API is hosted on http://127.0.0.1:5000/ locally. Authentication : This API requires no keys.
1.Questions 1. GET /questions 2. POST /questions 3. DELETE /questions/<question_id> 2.Quizzes 1. POST /quizzes 3.Categories 1. GET /categories 2. GET /categories/<category_id>/questions
Each ressource documentation is clearly structured:
- Description in a few words
curl
example that can directly be used in terminal- More descriptive explanation of input & outputs.
- Example Response.
- Error Handling (
curl
command to trigger error + error response)
Fetch paginated questions:
curl -X GET http://127.0.0.1:5000/questions:page=1
Fetches a list of dictionaries of questions in which the keys are the ids with all available fields, a list of all categories and number of total questions.
- Request Arguments:
- integer
page
(optional, 10 questions per page, defaults to1
if not given)
- integer
- Request Headers: None
- Returns:
- List of dict of questions with following fields:
- integer
id
- string
question
- string
answer
- string
category
- integer
difficulty
- integer
- list
categories
- list
current_category
- integer
total_questions
- boolean
success
- List of dict of questions with following fields:
{
"categories": [
"music",
"Art",
"Stories",
"Animation",
"design",
"Fashion"
],
"current_category": [
"Music",
],
"questions": [
{
"answer": "David Mark",
"category": 5,
"difficulty": 4,
"id": 2,
"question": "Who is the first man to win a nobel prize in physics?"
},
{
"answer": "Ronaldo",
"category": 5,
"difficulty": 4,
"id": 4,
"question": "Who is the best football player in the world?"
},
[...]
],
"success": true,
"total_questions": 19
}
A request with an invalid page will have the below respone:
curl -X GET http://127.0.0.1:5000/questions?page=124
will return
js
{
"error": 404,
"message": "Requested resource can not be found",
"success": false
}
# <a name="post-questions"></a>
### 2. POST /questions
Search Questions
```bash
curl -X POST http://127.0.0.1:5000/questions -d '{"searchTerm" : "love"}' -H 'Content-Type: application/json'
Create new Question
curl -X POST http://127.0.0.1:5000/questions -d '{ "question" : "Is there love in sharing?", "category" : "1" , "answer" : "Yes it is!", "difficulty" : 1 }' -H 'Content-Type: application/json'
- Searches database for questions with a search term, if provided. Otherwise, it will insert a new question into the database.
- Request Arguments: None
- Request Headers :
- if you want to search (application/json)
- string
searchTerm
(*required)
- string
- if you want to insert (application/json)
- string
question
(*required) - string
answer
(*required) - string
category
(*required) - integer
difficulty
(*required)
- string
- if you want to search (application/json)
- Returns:
- if you searched:
- List of dict of
questions
which match thesearchTerm
with following fields:- integer
id
- string
question
- string
answer
- string
category
- integer
difficulty
- integer
- List of dict of
current_category
with following fields:- integer
id
- string
type
- integer
- integer
total_questions
- boolean
success
- List of dict of
- if you inserted:
- List of dict of all questions with following fields:
- integer
id
- string
question
- string
answer
- string
category
- integer
difficulty
- integer
- integer
total_questions
- integer
created
id from inserted question - boolean
success
- List of dict of all questions with following fields:
- if you searched:
Search Questions
{
"current_category": [
{
"id": 1,
"type": "Science"
},
{
"id": 2,
"type": "Art"
},
[...] // all current categories
],
"questions": [
{
"answer": "Jup",
"category": 1,
"difficulty": 1,
"id": 24,
"question": "Is this a test question?"
}
.. with all questions that contains the search term
],
"success": true,
"total_questions": 6
}
Create Question
{
"question_id": 5, // id of question created
"success": True,
}
Search related
Searching for a question that does not exist return a 200 status code below:
curl -X POST http://127.0.0.1:5000/searchquestions -d '{"searchTerm" : "this does not exist"}' -H'Content-Type: application/json'
will return
{
"message":'No Result for searched question!'
"success":False
}
Insert related
If you try to insert a new question
, but forget to provide a required field, it will throw an 400
error:
curl -X POST http://127.0.0.1:5000/searchquestions -d '{ "question" : "Is this a question without an answer?", "category" : "1" , "difficulty" : 1 }' -H 'Content-Type: application/json'
will return
{
"error": 400,
"message": "Answer can not be blank",
"success": false
}
Delete Questions
curl -X DELETE http://127.0.0.1:5000/questions/10
- Deletes specific question based on given id
- Request Arguments:
- integer
question_id
- integer
- Request Headers : None
- Returns:
- integer
deleted
Id from deleted question. - boolean
success
- integer
{
"deleted": 10,
"success": true
}
If you try to delete a question
which does not exist, it will throw an 400
error:
curl -X DELETE http://127.0.0.1:5000/questions/7
will return
{
"error": 400,
"message": "Question with id 7 does not exist.",
"success": false
}
Play quiz game.
curl -X POST http://127.0.0.1:5000/quizzes -d '{"previous_questions" : [1, 2, 5], "quiz_category" : {"type" : "Science", "id" : "1"}} ' -H 'Content-Type: application/json'
- Plays quiz game by providing a list of already asked questions and a category to ask for a fitting, random question.
- Request Arguments: None
- Request Headers :
- list
previous_questions
with integer ids from already asked questions - dict
quiz_category
(optional) with keys:- string type
- integer id from category
- list
- Returns:
- Exactly one
question
as dict with following fields:- integer
id
- string
question
- string
answer
- string
category
- integer
difficulty
- integer
- boolean
success
- Exactly one
{
"question": {
"answer": "Yes",
"category": 1,
"difficulty": 1,
"id": 12,
"question": "Is udacity a good learning platform?"
},
"success": true
}
If you try to play the quiz game without a a valid JSON body, it will response with an 400
error.
curl -X POST http://127.0.0.1:5000/quizzes
will return
{
"error": 400,
"message": "Please provide a JSON body with previous question Ids and optional category.",
"success": false
}
Fetch all available categories
curl -X GET http://127.0.0.1:5000/categories
- Fetches a list of all
categories
with itstype
as values. - Request Arguments: None
- Request Headers : None
- Returns: A list of categories with its
type
as values and asuccess
value which indicates status of response.
{
"categories": [
"music",
"Art",
"Stories",
"Animation",
"design",
"Fashion"
],
"success": True
}
Get all questions from a specific category
.
curl -X GET http://127.0.0.1:5000/categories/2/questions?page=1
- Fetches all
questions
(paginated) from one specific category. - Request Arguments:
- integer
category_id
(*required) - integer
page
(optinal, 10 questions per Page, defaults to1
if not given)
- integer
- Request Headers: None
- Returns:
- integer
current_category
id from inputted category - List of dict of all questions with following fields:
- integer
id
- string
question
- string
answer
- string
category
- integer
difficulty
- integer
- integer
total_questions
- boolean
success
- integer
{
"current_category": "2",
"questions": [
{
"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?"
},
{
"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?"
}
],
"success": true,
"total_questions": 4
}
You get a 404 error when you query with a category that doesn't exist or for the wrong page:
curl -X GET http://127.0.0.1:5000/categories/10/questions?page=1
will return
{
"success": False,
"error": 404,
"message": "Requested resource can not be found"
}