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: docs/docs/05_flask_smorest/02_improvements_on_first_rest_api/README.md
+56-30Lines changed: 56 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -11,39 +11,16 @@ description: "Let's add a few routes to our first REST API, so it better matches
11
11
-[x] Create `end` folder
12
12
-[ ] Create per-file diff between `end` and `start` (use "Compare Folders")
13
13
14
-
## New files
14
+
## Starting code from section 4
15
15
16
-
Let's start off by creating a `requirements.txt` file with all our dependencies:
16
+
This is the "First REST API" project from Section 4:
17
17
18
-
```txt title="requirements.txt"
19
-
flask
20
-
flask-smorest
21
-
python-dotenv
22
-
```
23
-
24
-
We're adding `flask-smorest` to help us write REST APIs more easily, and generate documentation for us.
18
+
import Tabs from '@theme/Tabs';
19
+
import TabItem from '@theme/TabItem';
25
20
26
-
We're adding `python-dotenv` so it's easier for us to load environment variables and use the `.flaskenv` file.
27
-
28
-
Next, let's create the `.flaskenv` file:
29
-
30
-
```txt title=".flaskenv"
31
-
FLASK_APP=app
32
-
FLASK_ENV=development
33
-
```
34
-
35
-
If we have the `python-dotenv` library installed, when we run the `flask run` command, Flask will read the variables inside `.flaskenv` and use them to configure the Flask app.
36
-
37
-
The configuration that we'll do is to define the Flask app file (here, `app.py`). Then we'll also set the Flask environment to `development`, which does a couple things:
38
-
39
-
- Sets debug mode to true, which makes the app give us better error messages
40
-
- Sets the app reloading to true, so the app restarts when we make code changes
41
-
42
-
We don't want debug mode to be enabled in production (when we deploy our app), but while we're doing development it's definitely a time-saving tool!
43
-
44
-
## Code improvements
45
-
46
-
This is the "First REST API" project from Section 3:
21
+
<divclassName="codeTabContainer">
22
+
<Tabs>
23
+
<TabItemvalue="app"label="app.py"default>
47
24
48
25
```py title="app.py"
49
26
import uuid
@@ -105,6 +82,55 @@ def get_all_stores():
105
82
return {"stores": list(stores.value())}
106
83
```
107
84
85
+
</TabItem>
86
+
<TabItemvalue="docker"label="Dockerfile">
87
+
88
+
```docker
89
+
FROM python:3.10
90
+
EXPOSE 5000
91
+
WORKDIR /app
92
+
RUN pip install flask
93
+
COPY . .
94
+
CMD ["flask", "run", "--host", "0.0.0.0"]
95
+
```
96
+
97
+
</TabItem>
98
+
</Tabs>
99
+
</div>
100
+
101
+
102
+
## New files
103
+
104
+
Let's start off by creating a `requirements.txt` file with all our dependencies:
105
+
106
+
```txt title="requirements.txt"
107
+
flask
108
+
flask-smorest
109
+
python-dotenv
110
+
```
111
+
112
+
We're adding `flask-smorest` to help us write REST APIs more easily, and generate documentation for us.
113
+
114
+
We're adding `python-dotenv` so it's easier for us to load environment variables and use the `.flaskenv` file.
115
+
116
+
Next, let's create the `.flaskenv` file:
117
+
118
+
```txt title=".flaskenv"
119
+
FLASK_APP=app
120
+
FLASK_ENV=development
121
+
```
122
+
123
+
If we have the `python-dotenv` library installed, when we run the `flask run` command, Flask will read the variables inside `.flaskenv` and use them to configure the Flask app.
124
+
125
+
The configuration that we'll do is to define the Flask app file (here, `app.py`). Then we'll also set the Flask environment to `development`, which does a couple things:
126
+
127
+
- Sets debug mode to true, which makes the app give us better error messages
128
+
- Sets the app reloading to true, so the app restarts when we make code changes
129
+
130
+
We don't want debug mode to be enabled in production (when we deploy our app), but while we're doing development it's definitely a time-saving tool!
131
+
132
+
## Code improvements
133
+
108
134
### Creating a database file
109
135
110
136
First of all, let's move our "database" to another file.
0 commit comments