|
1 | 1 | # `03.3` Creating Your First Endpoint (route) |
2 | 2 |
|
3 | | -Since Flask is a server, it only makes sense to add some URLs to expose over the internet, for example: mydomain.com/hello |
| 3 | +Since Flask is a server, it only makes sense to add some URLs to expose over the internet, for example: `mydomain.com/hello` |
4 | 4 |
|
5 | | -As a developer, if we would like people to visit `http://mydomain.com/hello` and show a message like `Hello World` to those people, we have to add the following endpoint inside our app.py file: |
| 5 | +As a developer, if we would like people to visit `http://mydomain.com/hello` and show a message like `Hello World` to those people, we have to add the following endpoint inside our `app.py` file: |
6 | 6 |
|
7 | 7 | ```python |
8 | 8 | @app.route('/myroute', methods=['GET']) |
9 | 9 | def hello_world(): |
10 | | - return 'Hello, World!' |
| 10 | + return 'Hello World!' |
11 | 11 | ``` |
12 | 12 |
|
13 | | -+ The first part, `@app.route('/myroute')`, specifies the enpoint that will be available to our users. In this case, users would see `mydomain.com/myroute` when visiting this route. |
| 13 | ++ The first part, `@app.route('/myroute')`, specifies the endpoint that will be available to our users. In this case, users would see `mydomain.com/myroute` when visiting this route. |
14 | 14 |
|
15 | 15 | + The first line also specifies the methods that will be used with that URL. In this case, the `GET` method (for reading data). |
16 | 16 |
|
17 | | -+ The second line defines a function that will be called by Flask when that endpoint is called by the user (when the user requests `/blabla`). |
| 17 | ++ The second line defines a function that will be called by Flask when that endpoint is called by the user (when the user requests `/myroute`). |
18 | 18 |
|
19 | | -+ The third line defines our function execution and in this case, returns the text "Hello World" to the requesting client or browser. |
| 19 | ++ The third line defines our function execution and in this case, returns the text "Hello World!" to the requesting client or browser. |
20 | 20 |
|
21 | | -## 📝Instructions: |
| 21 | +## 📝 Instructions: |
22 | 22 |
|
23 | 23 | 1. Using that knowledge, make your server return the string `"<h1>Hello!</h1>"` when the URL `/todos` is typed on the browser. |
24 | 24 |
|
25 | 25 | 2. Please make sure that these two lines stay at the bottom of your `app.py` file. All routing and functions must remain above these two lines. |
26 | 26 |
|
27 | 27 | ```python |
28 | 28 | if __name__ == '__main__': |
29 | | - app.run(host='0.0.0.0', port=3245, debug=True) |
| 29 | + app.run(host='0.0.0.0', port=3245, debug=True) |
30 | 30 | ``` |
0 commit comments