From 3a2cdbec125f53169325d1f2faa0de4866ad7320 Mon Sep 17 00:00:00 2001 From: codebasics Date: Mon, 23 Aug 2021 16:52:29 -0400 Subject: [PATCH] fast api tutorial --- Advanced/FastAPI/main.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Advanced/FastAPI/main.py diff --git a/Advanced/FastAPI/main.py b/Advanced/FastAPI/main.py new file mode 100644 index 00000000..e385d0ff --- /dev/null +++ b/Advanced/FastAPI/main.py @@ -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) } +