Skip to content

Commit

Permalink
fast api tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
codebasics committed Aug 23, 2021
1 parent 21a0f10 commit 3a2cdbe
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Advanced/FastAPI/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from fastapi import FastAPI

from enum import Enum

app = FastAPI()

@app.get("/hello")
async def hello():
return "Welcome"

@app.get("/hello/{name}")
async def hello(name):
return f"Welcome {name}"

class AvailableCuisines(str, Enum):
indian = "indian"
american = "american"
italian = "italian"

food_items = {
'indian' : [ "Samosa", "Dosa" ],
'american' : [ "Hot Dog", "Apple Pie"],
'italian' : [ "Ravioli", "Pizza"]
}

@app.get("/get_items/{cuisine}")
async def get_items(cuisine: AvailableCuisines):
return food_items.get(cuisine)


coupon_code = {
1: '10%',
2: '20%',
3: '30%'
}

@app.get("/get_coupon/{code}")
async def get_items(code: int):
return { 'discount_amount': coupon_code.get(code) }

0 comments on commit 3a2cdbe

Please sign in to comment.