Skip to content

Commit 4317f8d

Browse files
committed
Clean up and added README file
1 parent 32ea94a commit 4317f8d

File tree

3 files changed

+377
-161
lines changed

3 files changed

+377
-161
lines changed

README_API.md

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
Getting Started
2+
Install the dependencies for the project:
3+
Run the commands: pip3 install -r requirements.txt from the directory "./backend" and npm install from the directory "./forntend"
4+
5+
To start the backend server:
6+
Run the command: flask run --reload from the directory "./backend"
7+
To start the frontend server:
8+
Run the command: npm start from the directory "./frontend"
9+
10+
Base URL: At present this app can only be run locally and is not hosted as a base URL. The backend app is hosted at the default, http://127.0.0.1:5000/, which is set as a proxy in the frontend configuration.
11+
Authentication: This version of the application does not require authentication or API keys.
12+
13+
Error Handling
14+
15+
Errors are returned as JSON objects in the following format:
16+
17+
{
18+
"success": False,
19+
"error": 400,
20+
"message": "bad request"
21+
}
22+
23+
The API will return four error types when requests fail:
24+
25+
400: Bad Request
26+
404: Resource Not Found
27+
422: Not Processable
28+
405: Method Not Allowed
29+
30+
Endpoints
31+
GET /categories
32+
General:
33+
Returns a list of all categories, if no categories are found it returns an 404 error
34+
Sample: curl -L "http://localhost:5000/categories"
35+
36+
"categories": {
37+
"1": "Science",
38+
"2": "Art",
39+
"3": "Geography",
40+
"4": "History",
41+
"5": "Entertainment",
42+
"6": "Sports"
43+
}
44+
45+
46+
GET /questions
47+
General:
48+
Returns a list of questions based on the the cuurent category, if no questions are found for that category it returns an 404 error
49+
Results are paginated in groups of 10. Include a request argument to choose page number, starting from 1.
50+
Sample: curl -L "http://localhost:5000/questions"
51+
52+
{
53+
"categories": {
54+
"1": "Science",
55+
"2": "Art",
56+
"3": "Geography",
57+
"4": "History",
58+
"5": "Entertainment",
59+
"6": "Sports"
60+
},
61+
"current_category": "Science",
62+
"questions": [
63+
{
64+
"answer": "The Liver",
65+
"category": 1,
66+
"difficulty": 4,
67+
"id": 20,
68+
"question": "What is the heaviest organ in the human body?"
69+
},
70+
{
71+
"answer": "Alexander Fleming",
72+
"category": 1,
73+
"difficulty": 3,
74+
"id": 21,
75+
"question": "Who discovered penicillin?"
76+
},
77+
{
78+
"answer": "Blood",
79+
"category": 1,
80+
"difficulty": 4,
81+
"id": 22,
82+
"question": "Hematology is a branch of medicine involving the study of what?"
83+
}
84+
],
85+
"total_questions": 20
86+
}
87+
88+
DELETE /questions/<int:question_id>
89+
General:
90+
Deletes a question based on its id , then returns the deleted question id and a list of questions , if the question to be deleted is not found in the database it returns an 404 error
91+
Results are paginated in groups of 10. Include a request argument to choose page number, starting from 1.
92+
Sample: curl -L -X DELETE "http://localhost:5000/questions/25"
93+
94+
{
95+
"deleted": 25,
96+
"question": [
97+
{
98+
"answer": "Apollo 13",
99+
"category": 5,
100+
"difficulty": 4,
101+
"id": 2,
102+
"question": "What movie earned Tom Hanks his third straight Oscar nomination, in 1996?"
103+
},
104+
{
105+
"answer": "Tom Cruise",
106+
"category": 5,
107+
"difficulty": 4,
108+
"id": 4,
109+
"question": "What actor did author Anne Rice first denounce, then praise in the role of her beloved Lestat?"
110+
},
111+
{
112+
"answer": "Maya Angelou",
113+
"category": 4,
114+
"difficulty": 2,
115+
"id": 5,
116+
"question": "Whose autobiography is entitled 'I Know Why the Caged Bird Sings'?"
117+
},
118+
{
119+
"answer": "Edward Scissorhands",
120+
"category": 5,
121+
"difficulty": 3,
122+
"id": 6,
123+
"question": "What was the title of the 1990 fantasy directed by Tim Burton about a young man with multi-bladed appendages?"
124+
},
125+
{
126+
"answer": "Muhammad Ali",
127+
"category": 4,
128+
"difficulty": 1,
129+
"id": 9,
130+
"question": "What boxer's original name is Cassius Clay?"
131+
},
132+
{
133+
"answer": "Brazil",
134+
"category": 6,
135+
"difficulty": 3,
136+
"id": 10,
137+
"question": "Which is the only team to play in every soccer World Cup tournament?"
138+
},
139+
{
140+
"answer": "Uruguay",
141+
"category": 6,
142+
"difficulty": 4,
143+
"id": 11,
144+
"question": "Which country won the first ever soccer World Cup in 1930?"
145+
},
146+
{
147+
"answer": "George Washington Carver",
148+
"category": 4,
149+
"difficulty": 2,
150+
"id": 12,
151+
"question": "Who invented Peanut Butter?"
152+
},
153+
{
154+
"answer": "Lake Victoria",
155+
"category": 3,
156+
"difficulty": 2,
157+
"id": 13,
158+
"question": "What is the largest lake in Africa?"
159+
},
160+
{
161+
"answer": "The Palace of Versailles",
162+
"category": 3,
163+
"difficulty": 3,
164+
"id": 14,
165+
"question": "In which royal palace would you find the Hall of Mirrors?"
166+
}
167+
]
168+
}
169+
170+
POST /questions
171+
General:
172+
Adds a question to the database, returns a list of questions based on the category of the new question , if no questions are found in the database it returns an 404 error
173+
Results are paginated in groups of 10. Include a request argument to choose page number, starting from 1.
174+
Sample: curl -L "http://localhost:5000/questions" -H "Content-Type: application/json" -d "{
175+
\"question\":\"In what year did the Titanic sink?\",
176+
\"answer\":\"1912\",
177+
\"category\":4,
178+
\"difficulty\":2
179+
}"
180+
181+
{
182+
"created": 29,
183+
"question": [
184+
{
185+
"answer": "Maya Angelou",
186+
"category": 4,
187+
"difficulty": 2,
188+
"id": 5,
189+
"question": "Whose autobiography is entitled 'I Know Why the Caged Bird Sings'?"
190+
},
191+
{
192+
"answer": "Muhammad Ali",
193+
"category": 4,
194+
"difficulty": 1,
195+
"id": 9,
196+
"question": "What boxer's original name is Cassius Clay?"
197+
},
198+
{
199+
"answer": "George Washington Carver",
200+
"category": 4,
201+
"difficulty": 2,
202+
"id": 12,
203+
"question": "Who invented Peanut Butter?"
204+
},
205+
{
206+
"answer": "Scarab",
207+
"category": 4,
208+
"difficulty": 4,
209+
"id": 23,
210+
"question": "Which dung beetle was worshipped by the ancient Egyptians?"
211+
},
212+
{
213+
"answer": "1912",
214+
"category": 4,
215+
"difficulty": 2,
216+
"id": 28,
217+
"question": "In what year did the Titanic sink?"
218+
},
219+
{
220+
"answer": "1912",
221+
"category": 4,
222+
"difficulty": 2,
223+
"id": 29,
224+
"question": "In what year did the Titanic sink?"
225+
}
226+
]
227+
}
228+
229+
POST /questions
230+
General:
231+
Searchs the database for a question, returns a list of questions based on the search term
232+
Sample: curl -L "http://localhost:5000/questions" -H "Content-Type: application/json" -d "{
233+
\"searchTerm\":\"title\"}"
234+
235+
{
236+
"questions": [
237+
{
238+
"answer": "Maya Angelou",
239+
"category": 4,
240+
"difficulty": 2,
241+
"id": 5,
242+
"question": "Whose autobiography is entitled 'I Know Why the Caged Bird Sings'?"
243+
},
244+
{
245+
"answer": "Edward Scissorhands",
246+
"category": 5,
247+
"difficulty": 3,
248+
"id": 6,
249+
"question": "What was the title of the 1990 fantasy directed by Tim Burton about a young man with multi-bladed appendages?"
250+
}
251+
]
252+
}
253+
254+
GET /categories/<int:category_id>/questions
255+
General:
256+
Gets questions based on the categories id , returns a list of questions based on the category , if no questions are found in the database then returns an 404 error
257+
Sample: curl -L "http://localhost:5000/categories/3/questions"
258+
259+
{
260+
"current_category": "Geography",
261+
"questions": [
262+
{
263+
"answer": "Lake Victoria",
264+
"category": 3,
265+
"difficulty": 2,
266+
"id": 13,
267+
"question": "What is the largest lake in Africa?"
268+
},
269+
{
270+
"answer": "The Palace of Versailles",
271+
"category": 3,
272+
"difficulty": 3,
273+
"id": 14,
274+
"question": "In which royal palace would you find the Hall of Mirrors?"
275+
},
276+
{
277+
"answer": "Agra",
278+
"category": 3,
279+
"difficulty": 2,
280+
"id": 15,
281+
"question": "The Taj Mahal is located in which Indian city?"
282+
}
283+
],
284+
"total_questions": 3
285+
}
286+
287+
POST /quizzes
288+
General:
289+
Gets a question based on previous questions and category , returns a random question of the same category , if no questions are found in the database then returns an 404 error
290+
Sample: curl -L "http://localhost:5000/quizzes" -H "Content-Type: application/json" -d "{\"previous_questions\": [1],\"quiz_category\":{\"id\": 1}}"
291+
292+
{
293+
"question": {
294+
"answer": "Alexander Fleming",
295+
"category": 1,
296+
"difficulty": 3,
297+
"id": 21,
298+
"question": "Who discovered penicillin?"
299+
}
300+
}
301+

0 commit comments

Comments
 (0)