|
1 | | -# `03.3` You first Endpoint (route) |
| 1 | +# `03.3` Creating Your First Endpoint (route) |
2 | 2 |
|
3 | | -Being Flask a server, it does not make sense not to add any URLs to expose over the internet, for example: |
| 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 for people to visit http://mydomain.com/hello and get a message `Hello World`, we would have to add the following endpoint to the 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 | | -@app.route('/blabla', methods=['GET']) |
| 8 | +@app.route('/myroute', methods=['GET']) |
9 | 9 | def hello_world(): |
10 | 10 | return 'Hello, World!' |
11 | 11 | ``` |
12 | 12 |
|
13 | | -+ The first line `@app.route('/blabla')` specifies the enpoint that will be available from now on, in this case `mydomain.com/blabla`. |
| 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. |
14 | 14 |
|
15 | | -+ The first line also specifies the methods that will be used with that URL, in this case `GET` method (for reading). |
| 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 | 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`). |
18 | 18 |
|
19 | | -+ The third line 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 | 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 | | -2. Please make sure that this lines keep being the last two lines of your `app.py` file. |
| 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__': |
|
0 commit comments