Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # --------------------------------------------------------------------------------------------------------------------------
- # Random Fast API application lmao
- from fastapi import FastAPI
- from pydantic import BaseModel
- app = FastAPI()
- class BioSummary(BaseModel):
- name: str
- age: int
- hobbies: list
- fav_food: str
- school: str
- @app.get("/")
- async def root():
- return {"message": "Hello World"}
- @app.get("/hello/{name}")
- async def say_hello(name: str):
- return {"message": f"Hello {name}"}
- @app.post('/bio/create')
- async def create_bio(summary: BioSummary):
- hobbies = []
- if not len(summary.hobbies) == 1:
- for h in range(len(summary.hobbies)):
- if h == len(summary.hobbies) - 1:
- hobbies.append(f'and {summary.hobbies[h]}')
- else:
- hobbies.append(summary.hobbies[h]+",")
- else:
- hobbies.append(summary.hobbies[0])
- bio = f'Hello, my name is {summary.name}, I am {summary.age} and my hobbies are {" ".join(hobbies)}. My favourite food is {summary.fav_food} and I go to {summary.school}.'
- return bio
Add Comment
Please, Sign In to add comment