Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f01cad0

Browse files
Update depencencies
1 parent c6f2fb2 commit f01cad0

File tree

11 files changed

+81
-1252
lines changed

11 files changed

+81
-1252
lines changed

‎.idea/.gitignore‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎.idea/.name‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

‎.idea/ruff.xml‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 85 deletions
This file was deleted.

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

Lines changed: 0 additions & 1000 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 = (
12+
'<html>'
13+
"<body style='padding: 10px;'>"
14+
'<h1>Welcome to the API</h1>'
15+
'<div>'
16+
"Try it: <a href='/api/calculate?x=7&y=11'>/api/calculate?x=7&y=11</a>"
17+
'</div>'
18+
'</body>'
19+
'</html>'
20+
)
21+
22+
return fastapi.responses.HTMLResponse(content=body)
23+
24+
25+
@api.get('/api/calculate')
26+
def calculate(x: int, y: int, z: Optional[int] = None):
27+
if z == 0:
28+
return fastapi.responses.JSONResponse(content={'error': 'ERROR: Z cannot be zero.'}, status_code=400)
29+
30+
value = x + y
31+
32+
if z is not None:
33+
value /= z
34+
35+
return {'x': x, 'y': y, 'z': z, 'value': value}
36+
37+
38+
# uvicorn was updated, and it's type definitions don't match FastAPI,
39+
# but the server and code still work fine. So ignore PyCharm's warning:
40+
# noinspection PyTypeChecker
41+
uvicorn.run(api, port=8000, host='127.0.0.1')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fastapi
2+
uvicorn
3+
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
1-
apistar==0.5.41
2-
pytest
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile requirements.piptools --output-file requirements.txt
3+
annotated-types==0.6.0
4+
# via pydantic
5+
anyio==4.3.0
6+
# via starlette
7+
click==8.1.7
8+
# via uvicorn
9+
fastapi==0.110.1
10+
h11==0.14.0
11+
# via uvicorn
12+
idna==3.6
13+
# via anyio
14+
pydantic==2.6.4
15+
# via fastapi
16+
pydantic-core==2.16.3
17+
# via pydantic
18+
sniffio==1.3.1
19+
# via anyio
20+
starlette==0.37.2
21+
# via fastapi
22+
typing-extensions==4.11.0
23+
# via
24+
# fastapi
25+
# pydantic
26+
# pydantic-core
27+
uvicorn==0.29.0

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

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /