Skip to content

Commit 883632b

Browse files
committedApr 24, 2024
switch the days 9-12 code and demo to match what is now in the course (fastapi)
1 parent c6f2fb2 commit 883632b

File tree

15 files changed

+95
-1265
lines changed

15 files changed

+95
-1265
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,4 @@ days/013-016-css-basics/demos/selectorville/.idea/encodings.xml
172172
days/013-016-css-basics/demos/selectorville/.idea/selectorville.iml
173173
**.DS_Store
174174
days/041-044-react/**node_modules
175+
ruff.xml

‎.idea/100 days web course.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎days/001-004-flask-intro/code/demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from program import app
1+
from program import app # noqa: F401
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from flask import Flask
2+
from program import routes # noqa: F401
23

34
app = Flask(__name__)
45

5-
from program import routes
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
click
2+
Flask
3+
itsdangerous
4+
Jinja2
5+
MarkupSafe
6+
python-dotenv
7+
werkzeug
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
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

‎days/005-008-html5/demos/yahoo_clone/.idea/dictionaries/mkennedy.xml

-8
This file was deleted.

‎days/005-008-html5/demos/yahoo_clone/.idea/encodings.xml

-4
This file was deleted.

‎days/009-012-modern-apis-starred/demo/app.py

-85
This file was deleted.

‎days/009-012-modern-apis-starred/demo/cars.json

-1,000
This file was deleted.

‎days/009-012-modern-apis-starred/demo/requirements.txt

-2
This file was deleted.

‎days/009-012-modern-apis-starred/demo/test_app.py

-155
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fastapi
2+
uvicorn
3+

‎days/009-012-modern-apis-starred/readme.md ‎days/009-012-modern-apis-with-fastapi/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Days 09-12 Building APIs with Api Star (0.5.41)
1+
# Days 09-12 Building APIs with FastAPI
22

33
**Important**: at the time of recording the newest version of `apistar` was `0.5.41`, which let you build complete APIs.
44

0 commit comments

Comments
 (0)
Failed to load comments.