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
Now... if we want to finish the post, we have to perform these specific actions:
4
-
5
-
+ First make sure that you are converting the request body into a real python data structure, like a dictionary. We already used `request.json` for that, since we know that the request will be in format application/json. If that is not known, you may want to use `request.get_json(force=True)` to ignore the content type and treat it like json.
6
-
7
-
+ Add the dictionary into the list of `todos`.
8
-
9
-
+ Return the new list of `todos`.
10
-
11
3
Your code should look like this by now:
12
4
13
5
```python
@@ -17,12 +9,19 @@ def add_new_todo():
17
9
request_body = request.json
18
10
print("Incoming request with the following body", request_body)
19
11
return'Response for the POST todo'
20
-
21
12
```
22
13
23
-
Obviously this endopint is currently not adding anything new to our 'database' (the `todo` list).
14
+
Now... if we want to finish our `POST` method, we have to perform the following specific actions:
15
+
16
+
+ First: Make sure that you are converting the request body into a real python data structure, like a dictionary. You can see that we already used `request.json` for that since we know the request will be in application/json. However, if that is not known, you may want to use `request.get_json(force=True)` to ignore the content type and treat it like json.
17
+
18
+
+ Second: Add the dictionary into the list of `todos`.
19
+
20
+
+ Last: Return the new list of `todos`.
21
+
22
+
Currently, this endopint is not adding anything new to our 'database' (the `todo` list).
24
23
25
-
Let's complete the code so the endpoint can do its job - add a new task to the `todos`.
24
+
Let's complete our code so the endpoint can do its job - add a new task to the `todos` list.
26
25
27
26
28
27
## 📝 Instructions:
@@ -31,4 +30,4 @@ Let's complete the code so the endpoint can do its job - add a new task to the `
31
30
32
31
2. Return the updated list `todos` to the front end.
33
32
34
-
3. Do not forget to `jsonify` your return. Why is this necessary - discuss with the class.
33
+
3. Do not forget to `jsonify` your return. Why is this necessary? Ask instructor to discuss with the class.
0 commit comments