Last active
April 14, 2024 11:35
-
-
Save deepanshumehtaa/d4f3a676bb2890c3866ad0cabeaf2328 to your computer and use it in GitHub Desktop.
bare fastApi server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uvicorn main:app --reload | |
# venv\Scripts\activate | |
from fastapi import FastAPI, Body | |
from pydantic import BaseModel | |
app = FastAPI() | |
@app.get("/") | |
async def root(): | |
return {"SUCCESS": True} | |
@app.get("/get") | |
async def get_params( | |
fname_qparam: str, | |
lname_qparam: str, | |
): | |
return {"message": f"Hello {fname_qparam} {lname_qparam}"} | |
@app.get("/get/many") | |
async def get_many( | |
fname_qparam: str, | |
lname_qparam: str, | |
): | |
return [ | |
{"msg1": fname_qparam}, | |
{"msg2": lname_qparam}, | |
] | |
db = [] | |
class Item(BaseModel): | |
author: str | |
description: str | None = None | |
@app.post("/post") | |
async def post_it( | |
item: Item = Body(), | |
): | |
db.append(item) | |
return { | |
"msg": "data created", | |
"data": db, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment