Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pulling the req for read me #46

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 229 additions & 17 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,244 @@ One note before you delve into your tasks: for each endpoint, you are expected t
8. Create a `POST` endpoint to get questions to play the quiz. This endpoint should take a category and previous question parameters and return a random questions within the given category, if provided, and that is not one of the previous questions.
9. Create error handlers for all expected errors including 400, 404, 422, and 500.

## Documenting your Endpoints
### API Documentation

You will need to provide detailed documentation of your API endpoints including the URL, request parameters, and the response body. Use the example below as a reference.
****
GET "\categories"
curl -X GET 'http://127.0.0.1:5000/categories'

### Documentation Example
- Fetches a dictionary of categories in which the keys are the ids and the value is the corresponding string of the category
- Request Parameters: None
- Response Body:

`GET '/api/v1.0/categories'`
categories: A dictionary containing Category ID and Category Type as a key value pair

- 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"
},
"success": true
}

****
GET "\questions?page=<page_number>"
curl -X GET 'http://127.0.0.1:5000/questions'
curl -X GET 'http://127.0.0.1:5000/questions?page=2'

- Fetches a paginated dictionary of questions of all available categories. A page contains 10 questions.
- Request parameters (optional): page number in integer
- Response Body:

categories: A dictionary containing Category ID and Category Type as a key value pair
current_category: Null
questions: List of questions
total_questions: Total Number of questions

```json
{
"1": "Science",
"2": "Art",
"3": "Geography",
"4": "History",
"5": "Entertainment",
"6": "Sports"
"categories": {
"1": "Science",
"2": "Art",
"3": "Geography",
"4": "History",
"5": "Entertainment",
"6": "Sports"
},
"current_category": null,
"questions": [
{
"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": "Maya Angelou",
"category": 4,
"difficulty": 2,
"id": 5,
"question": "Whose autobiography is entitled 'I Know Why the Caged Bird Sings'?"
},
{
"answer": "Edward Scissorhands",
"category": 5,
"difficulty": 3,
"id": 6,
"question": "What was the title of the 1990 fantasy directed by Tim Burton about a young man with multi-bladed appendages?"
},
{
"answer": "Brazil",
"category": 6,
"difficulty": 3,
"id": 10,
"question": "Which is the only team to play in every soccer World Cup tournament?"
},
{
"answer": "Uruguay",
"category": 6,
"difficulty": 4,
"id": 11,
"question": "Which country won the first ever soccer World Cup in 1930?"
},
{
"answer": "George Washington Carver",
"category": 4,
"difficulty": 2,
"id": 12,
"question": "Who invented Peanut Butter?"
},
{
"answer": "Lake Victoria",
"category": 3,
"difficulty": 2,
"id": 13,
"question": "What is the largest lake in Africa?"
},
{
"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\u2013initials M C was a creator of optical illusions?"
},
{
"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": 46
}
```

## Testing
****
DELETE "/questions/<question_id>"
curl -X DELETE 'http://127.0.0.1:5000/questions/2'

- Delete an existing questions from the available questions based on the question ID
- Request Parameters: question_id in integer that needs to be deleted
- Response Body:

deleted: Question ID that is deleted
{
"deleted": "49",
"success": true
}

****
POST /questions
curl -X POST -H "Content-Type: application/json" -d '{"question":"What is the capital city of India?", "answer":"New Delhi", "difficulty":2, "category":3}' 'http://127.0.0.1:5000/questions'


- Add a new question to the list of available questions
- Request Paremeter: Need to provide the new question and its answer, difficulty level and category ID in the following format
{question:string, answer:string, difficulty:int, category:int}
- Response Body:

created: Question ID that is created
{
"created": 91,
"success": true
}

****
POST "/questions/search"
curl -X POST -H "Content-Type: application/json" -d '{"searchTerm":"Taj"}' 'http://127.0.0.1:5000/questions/search'

- Fetches all questions based on the search string provided (not case-sensitive)
- Request body: Need to provide the search string in the following format
{searchTerm:string}
- Response Body:

current_category: Null
questions: List of questions having the search string (not case sensitive)
total_questions: Total Number of questions having the search string
{
"current_category": null,
"questions": [
{
"answer": "Agra",
"category": 3,
"difficulty": 2,
"id": 15,
"question": "The Taj Mahal is located in which Indian city?"
}
],
"success": true,
"total_questions": 1
}

****
GET "/categories/<int:category_id>/questions"
curl -X GET 'http://127.0.0.1:5000/categories/2/questions'

- Fetches a dictionary of questions for the given category ID
- Request Parameter: Category ID for questions should be in integer
- Response Body:

Write at least one test for the success and at least one error behavior of each endpoint using the unittest library.
current_category: Current category ID
questions: List of questions under the given category
total_questions: Total Number of questions under the given category
{
"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": "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": 2
}

****
POST "/quizzes"
For a particular category :
curl -X POST -H "Content-Type: application/json" -d '{"previous_questions": [], "quiz_category": {"type": "Sports", "id": "6"}}' 'http://127.0.0.1:5000/quizzes'
For All categories:
curl -X POST -H "Content-Type: application/json" -d '{"previous_questions": [], "quiz_category": {"type": "click", "id": 0}}' 'http://127.0.0.1:5000/quizzes'

- Fetches one random question within a specified category or all categories based on the option chosen. It does not repeat the previous question.
- Request Parameter: The request parameter consists of previous questions and quiz category containing category ID and category type
{previous_questions: arr, quiz_category: {id:int, type:string}}
- Response Body:

question: Random questions under the given or any category based on the option chosen
{
"question": {
"answer": "The Liver",
"category": 1,
"difficulty": 4,
"id": 20,
"question": "What is the heaviest organ in the human body?"
},
"success": true
}
## Testing

To deploy the tests, run

Expand Down
Loading
Loading