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: .learn/exercises/07-post_todo/README.md
+13-11Lines changed: 13 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,12 +8,12 @@ POST /todos
8
8
DELETE /todos
9
9
```
10
10
11
-
In order to build the `POST /todos` endpoint, we have to do something similar to what we did in the first endpoint with our GET method. Remember that each endpoint in a Flask API is represented by decorator `@app.route()`and a function`def my_function():` like this:
11
+
In order to build the `POST /todos` endpoint, we have to do something similar to what we did in the first endpoint with our GET method. Remember that each endpoint in a Flask API is represented by decorator and a function, like this:
12
12
13
13
```python
14
14
@app.route('/myroute', methods=['GET'])
15
15
defhello_world():
16
-
return'Hello, World!'
16
+
return'Hello World!'
17
17
```
18
18
19
19
In this case, we are not going to be expecting a `GET` request, but rather a `POST` request.
@@ -23,19 +23,13 @@ Also, we are expecting to receive the TODO that the client wants to add inside o
23
23
```python
24
24
from flask import request
25
25
26
-
# The request body is already JSON decoded, and it comes in the request.json variable
27
-
print(request.json)
26
+
# The request body is already JSON decoded, and it comes in the request.data variable
27
+
print(request.data)
28
28
```
29
29
30
30
## 📝 Instructions:
31
31
32
-
1. Remember to import `request` at the top of the file:
33
-
34
-
```python
35
-
from flask import request
36
-
```
37
-
38
-
2. Then, add the following endpoint to your app.py and test it:
32
+
1. Add the following endpoint to your `app.py` and test it:
39
33
40
34
```python
41
35
@app.route('/todos', methods=['POST'])
@@ -44,3 +38,11 @@ def add_new_todo():
44
38
print("Incoming request with the following body", request_body)
45
39
return'Response for the POST todo'
46
40
```
41
+
42
+
2. Remember to import `request` at the top of the file:
0 commit comments