File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments