You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: backend/README.md
+28-34Lines changed: 28 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Backend - Trivia API
2
2
3
-
## Installing Dependencies for the Backend
3
+
## Setting up the Backend
4
4
5
-
### Installing Dependencies
5
+
### Install Dependencies
6
6
7
7
1.**Python 3.7** - Follow instructions to install the latest version of python for your platform in the [python docs](https://docs.python.org/3/using/unix.html#getting-and-installing-the-latest-version-of-python)
-[Flask](http://flask.pocoo.org/) is a lightweight backend microservices framework. Flask is required to handle requests and responses.
20
20
21
-
-[SQLAlchemy](https://www.sqlalchemy.org/) is the Python SQL toolkit and ORM we'll use handle the lightweight sqlite database. You'll primarily work in app.pyand can reference models.py.
21
+
-[SQLAlchemy](https://www.sqlalchemy.org/) is the Python SQL toolkit and ORM we'll use to handle the lightweight SQL database. You'll primarily work in `app.py`and can reference `models.py`.
22
22
23
-
-[Flask-CORS](https://flask-cors.readthedocs.io/en/latest/#) is the extension we'll use to handle crossorigin requests from our frontend server.
23
+
-[Flask-CORS](https://flask-cors.readthedocs.io/en/latest/#) is the extension we'll use to handle cross-origin requests from our frontend server.
24
24
25
-
### Database Setup
25
+
### Set up the Database
26
26
27
27
With Postgres running, create a `trivia` database:
28
28
@@ -36,7 +36,7 @@ Populate the database using the `trivia.psql` file provided. From the `backend`
36
36
psql trivia < trivia.psql
37
37
```
38
38
39
-
### Running the server
39
+
### Run the Server
40
40
41
41
From within the `./src` directory first ensure you are working using your created virtual environment.
42
42
@@ -58,49 +58,43 @@ These are the files you'd want to edit in the backend:
58
58
One note before you delve into your tasks: for each endpoint, you are expected to define the endpoint and response data. The frontend will be a plentiful resource because it is set up to expect certain endpoints and response data formats already. You should feel free to specify endpoints in your own way; if you do so, make sure to update the frontend or you will get some unexpected behavior.
59
59
60
60
1. Use Flask-CORS to enable cross-domain requests and set response headers.
61
-
62
-
2. Create an endpoint to handle GET requests for questions, including pagination (every 10 questions). This endpoint should return a list of questions, number of total questions, current category, categories.
63
-
64
-
3. Create an endpoint to handle GET requests for all available categories.
65
-
66
-
4. Create an endpoint to DELETE question using a question ID.
67
-
68
-
5. Create an endpoint to POST a new question, which will require the question and answer text, category, and difficulty score.
69
-
70
-
6. Create a POST endpoint to get questions based on category.
71
-
72
-
7. Create a POST endpoint to get questions based on a search term. It should return any questions for whom the search term is a substring of the question.
73
-
74
-
8. Create a POST endpoint to get questions to play the quiz. This endpoint should take 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.
75
-
76
-
9. Create error handlers for all expected errors including 400, 404, 422 and 500.
61
+
2. Create an endpoint to handle `GET` requests for questions, including pagination (every 10 questions). This endpoint should return a list of questions, number of total questions, current category, categories.
62
+
3. Create an endpoint to handle `GET` requests for all available categories.
63
+
4. Create an endpoint to `DELETE` a question using a question `ID`.
64
+
5. Create an endpoint to `POST` a new question, which will require the question and answer text, category, and difficulty score.
65
+
6. Create a `POST` endpoint to get questions based on category.
66
+
7. Create a `POST` endpoint to get questions based on a search term. It should return any questions for whom the search term is a substring of the question.
67
+
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.
68
+
9. Create error handlers for all expected errors including 400, 404, 422, and 500.
77
69
78
70
## Documenting your Endpoints
79
71
80
-
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.
72
+
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.
81
73
82
74
### Documentation Example
83
75
84
-
GET `'/api/v1.0/categories'`
76
+
`GET '/api/v1.0/categories'`
85
77
86
78
- Fetches a dictionary of categories in which the keys are the ids and the value is the corresponding string of the category
87
79
- Request Arguments: None
88
-
- Returns: An object with a single key, categories, that contains a object of id: category_string key:value pairs.
89
-
90
-
```bash
91
-
{'1':"Science",
92
-
'2':"Art",
93
-
'3':"Geography",
94
-
'4':"History",
95
-
'5':"Entertainment",
96
-
'6':"Sports"}
80
+
- Returns: An object with a single key, `categories`, that contains an object of `id: category_string` key: value pairs.
81
+
82
+
```json
83
+
{
84
+
"1": "Science",
85
+
"2": "Art",
86
+
"3": "Geography",
87
+
"4": "History",
88
+
"5": "Entertainment",
89
+
"6": "Sports"
90
+
}
97
91
```
98
92
99
93
## Testing
100
94
101
95
Write at least one test for the success and at least one error behavior of each endpoint using the unittest library.
Copy file name to clipboardExpand all lines: frontend/README.md
+71-68Lines changed: 71 additions & 68 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Getting Setup
4
4
5
-
> _tip_: this frontend is designed to work with [Flask-based Backend](../backend) so it will not load successfully if the backend is not working or not connect. We recommend that you **stand up the backend first**, test using Postman or curl, update the endpoints in the frontend, and then the frontend should integrate smoothly.
5
+
> _tip_: this frontend is designed to work with [Flask-based Backend](../backend) so it will not load successfully if the backend is not working or not connected. We recommend that you **stand up the backend first**, test using Postman or curl, update the endpoints in the frontend, and then the frontend should integrate smoothly.
6
6
7
7
### Installing Dependencies
8
8
@@ -63,22 +63,24 @@ You can optionally update this game play to increase the number of questions or
63
63
64
64
> Only read the below to confirm your notes regarding the expected API endpoint behavior based on reading the frontend codebase.
65
65
66
-
**Here are the expected endpoints and behavior**:
66
+
### Expected endpoints and behaviors
67
67
68
68
`GET '/categories'`
69
69
70
70
- Fetches a dictionary of categories in which the keys are the ids and the value is the corresponding string of the category
71
71
- Request Arguments: None
72
72
- Returns: An object with a single key, categories, that contains an object of id: category_string key:value pairs.
73
73
74
-
```bash
74
+
```json
75
75
{
76
-
'categories': { '1':"Science",
77
-
'2':"Art",
78
-
'3':"Geography",
79
-
'4':"History",
80
-
'5':"Entertainment",
81
-
'6':"Sports" }
76
+
"categories": {
77
+
"1": "Science",
78
+
"2": "Art",
79
+
"3": "Geography",
80
+
"4": "History",
81
+
"5": "Entertainment",
82
+
"6": "Sports"
83
+
}
82
84
}
83
85
```
84
86
@@ -90,25 +92,27 @@ You can optionally update this game play to increase the number of questions or
90
92
- Request Arguments: `page` - integer
91
93
- Returns: An object with 10 paginated questions, total questions, object including all categories, and current category string
92
94
93
-
```bash
95
+
```json
94
96
{
95
-
'questions': [
96
-
{
97
-
'id': 1,
98
-
'question': 'This is a question',
99
-
'answer': 'This is an answer',
100
-
'difficulty': 5,
101
-
'category': 2
102
-
},
103
-
],
104
-
'totalQuestions': 100,
105
-
'categories': { '1':"Science",
106
-
'2':"Art",
107
-
'3':"Geography",
108
-
'4':"History",
109
-
'5':"Entertainment",
110
-
'6':"Sports" },
111
-
'currentCategory': 'History'
97
+
"questions": [
98
+
{
99
+
"id": 1,
100
+
"question": "This is a question",
101
+
"answer": "This is an answer",
102
+
"difficulty": 5,
103
+
"category": 2
104
+
}
105
+
],
106
+
"totalQuestions": 100,
107
+
"categories": {
108
+
"1": "Science",
109
+
"2": "Art",
110
+
"3": "Geography",
111
+
"4": "History",
112
+
"5": "Entertainment",
113
+
"6": "Sports"
114
+
},
115
+
"currentCategory": "History"
112
116
}
113
117
```
114
118
@@ -120,19 +124,19 @@ You can optionally update this game play to increase the number of questions or
120
124
- Request Arguments: `id` - integer
121
125
- Returns: An object with questions for the specified category, total questions, and current category string
122
126
123
-
```bash
127
+
```json
124
128
{
125
-
'questions': [
126
-
{
127
-
'id': 1,
128
-
'question': 'This is a question',
129
-
'answer': 'This is an answer',
130
-
'difficulty': 5,
131
-
'category': 4
132
-
},
133
-
],
134
-
'totalQuestions': 100,
135
-
'currentCategory': 'History'
129
+
"questions": [
130
+
{
131
+
"id": 1,
132
+
"question": "This is a question",
133
+
"answer": "This is an answer",
134
+
"difficulty": 5,
135
+
"category": 4
136
+
}
137
+
],
138
+
"totalQuestions": 100,
139
+
"currentCategory": "History"
136
140
}
137
141
```
138
142
@@ -151,7 +155,7 @@ You can optionally update this game play to increase the number of questions or
151
155
- Sends a post request in order to get the next question
152
156
- Request Body:
153
157
154
-
```bash
158
+
```json
155
159
{
156
160
'previous_questions': [1, 4, 20, 15]
157
161
quiz_category': 'current category'
@@ -160,15 +164,15 @@ You can optionally update this game play to increase the number of questions or
160
164
161
165
- Returns: a single new question object
162
166
163
-
```bash
167
+
```json
164
168
{
165
-
'question': {
166
-
'id': 1,
167
-
'question': 'This is a question',
168
-
'answer': 'This is an answer',
169
-
'difficulty': 5,
170
-
'category': 4
171
-
}
169
+
"question": {
170
+
"id": 1,
171
+
"question": "This is a question",
172
+
"answer": "This is an answer",
173
+
"difficulty": 5,
174
+
"category": 4
175
+
}
172
176
}
173
177
```
174
178
@@ -179,12 +183,12 @@ You can optionally update this game play to increase the number of questions or
179
183
- Sends a post request in order to add a new question
180
184
- Request Body:
181
185
182
-
```bash
186
+
```json
183
187
{
184
-
'question': 'Heres a new question string',
185
-
'answer': 'Heres a new answer string',
186
-
'difficulty': 1,
187
-
'category': 3,
188
+
"question": "Heres a new question string",
189
+
"answer": "Heres a new answer string",
190
+
"difficulty": 1,
191
+
"category": 3
188
192
}
189
193
```
190
194
@@ -197,27 +201,26 @@ You can optionally update this game play to increase the number of questions or
197
201
- Sends a post request in order to search for a specific question by search term
198
202
- Request Body:
199
203
200
-
```bash
204
+
```json
201
205
{
202
-
'searchTerm': 'this is the term the user is looking for'
206
+
"searchTerm": "this is the term the user is looking for"
203
207
}
204
-
205
208
```
206
209
207
210
- Returns: any array of questions, a number of totalQuestions that met the search term and the current category string
0 commit comments