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 3a2cdbe

Browse files
author
codebasics
committed
fast api tutorial
1 parent 21a0f10 commit 3a2cdbe

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎Advanced/FastAPI/main.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from fastapi import FastAPI
2+
3+
from enum import Enum
4+
5+
app = FastAPI()
6+
7+
@app.get("/hello")
8+
async def hello():
9+
return "Welcome"
10+
11+
@app.get("/hello/{name}")
12+
async def hello(name):
13+
return f"Welcome {name}"
14+
15+
class AvailableCuisines(str, Enum):
16+
indian = "indian"
17+
american = "american"
18+
italian = "italian"
19+
20+
food_items = {
21+
'indian' : [ "Samosa", "Dosa" ],
22+
'american' : [ "Hot Dog", "Apple Pie"],
23+
'italian' : [ "Ravioli", "Pizza"]
24+
}
25+
26+
@app.get("/get_items/{cuisine}")
27+
async def get_items(cuisine: AvailableCuisines):
28+
return food_items.get(cuisine)
29+
30+
31+
coupon_code = {
32+
1: '10%',
33+
2: '20%',
34+
3: '30%'
35+
}
36+
37+
@app.get("/get_coupon/{code}")
38+
async def get_items(code: int):
39+
return { 'discount_amount': coupon_code.get(code) }
40+

0 commit comments

Comments
(0)

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