15 files changed +95
-1265
lines changed Original file line number Diff line number Diff line change @@ -172,3 +172,4 @@ days/013-016-css-basics/demos/selectorville/.idea/encodings.xml
172
172
days /013-016-css-basics /demos /selectorville /.idea /selectorville.iml
173
173
** .DS_Store
174
174
days /041-044-react /** node_modules
175
+ ruff.xml
Original file line number Diff line number Diff line change 1
- from program import app
1
+ from program import app # noqa: F401
Original file line number Diff line number Diff line change 1
1
from flask import Flask
2
+ from program import routes # noqa: F401
2
3
3
4
app = Flask (__name__ )
4
5
5
- from program import routes
6
+
Original file line number Diff line number Diff line change
1
+ click
2
+ Flask
3
+ itsdangerous
4
+ Jinja2
5
+ MarkupSafe
6
+ python-dotenv
7
+ werkzeug
Original file line number Diff line number Diff line change 1
- click == 6.7
2
- Flask == 1.0.2
3
- itsdangerous == 0.24
4
- Jinja2 >= 2.10.1
5
- MarkupSafe == 1.0
6
- python-dotenv == 0.9.1
7
- werkzeug >= 0.15.3
1
+ #
2
+ # This file is autogenerated by pip-compile with Python 3.11
3
+ # by the following command:
4
+ #
5
+ # pip-compile requirements.piptools
6
+ #
7
+ blinker == 1.7.0
8
+ # via flask
9
+ click == 8.1.7
10
+ # via
11
+ # -r requirements.piptools
12
+ # flask
13
+ flask == 3.0.0
14
+ # via -r requirements.piptools
15
+ itsdangerous == 2.1.2
16
+ # via
17
+ # -r requirements.piptools
18
+ # flask
19
+ jinja2 == 3.1.2
20
+ # via
21
+ # -r requirements.piptools
22
+ # flask
23
+ markupsafe == 2.1.3
24
+ # via
25
+ # -r requirements.piptools
26
+ # jinja2
27
+ # werkzeug
28
+ python-dotenv == 1.0.0
29
+ # via -r requirements.piptools
30
+ werkzeug == 3.0.1
31
+ # via
32
+ # -r requirements.piptools
33
+ # flask
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ from typing import Optional
2
+
3
+ import fastapi
4
+ import uvicorn
5
+
6
+ api = fastapi .FastAPI ()
7
+
8
+
9
+ @api .get ('/' )
10
+ def index ():
11
+ body = "<html>" \
12
+ "<body style='padding: 10px;'>" \
13
+ "<h1>Welcome to the API</h1>" \
14
+ "<div>" \
15
+ "Try it: <a href='/api/calculate?x=7&y=11'>/api/calculate?x=7&y=11</a>" \
16
+ "</div>" \
17
+ "</body>" \
18
+ "</html>"
19
+
20
+ return fastapi .responses .HTMLResponse (content = body )
21
+
22
+
23
+ @api .get ('/api/calculate' )
24
+ def calculate (x : int , y : int , z : Optional [int ] = None ):
25
+ if z == 0 :
26
+ return fastapi .responses .JSONResponse (
27
+ content = {"error" : "ERROR: Z cannot be zero." },
28
+ status_code = 400 )
29
+
30
+ value = x + y
31
+
32
+ if z is not None :
33
+ value /= z
34
+
35
+ return {
36
+ 'x' : x ,
37
+ 'y' : y ,
38
+ 'z' : z ,
39
+ 'value' : value
40
+ }
41
+
42
+
43
+ # uvicorn was updated, and it's type definitions don't match FastAPI,
44
+ # but the server and code still work fine. So ignore PyCharm's warning:
45
+ # noinspection PyTypeChecker
46
+ uvicorn .run (api , port = 8000 , host = "127.0.0.1" )
Original file line number Diff line number Diff line change
1
+ fastapi
2
+ uvicorn
3
+
Original file line number Diff line number Diff line change 1
- # Days 09-12 Building APIs with Api Star (0.5.41)
1
+ # Days 09-12 Building APIs with FastAPI
2
2
3
3
** Important** : at the time of recording the newest version of ` apistar ` was ` 0.5.41 ` , which let you build complete APIs.
4
4
0 commit comments