FastAPI Example

This commit is contained in:
Alauddin Maulana Hirzan 2024-06-02 12:19:29 +07:00
parent 3cf5b88d61
commit 6913ed2583
Signed by: maulanahirzan
GPG key ID: 484DAC952787FA13
3 changed files with 27 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
__pycache__

View file

@ -0,0 +1,23 @@
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
app = FastAPI()
# Simple Endpoint
@app.get("/")
def read_root():
return {"Hello": "World"}
# Simple GET Endpoint
@app.get("/items")
def read_item(item1, item2, item3):
return {"item1": item1,
"item2": item2,
"item3": item3}
# Simple Endpoint with HTML Response
@app.get("/html")
def read_html():
html = """<html><body>Welcome</body></html>"""
return HTMLResponse(content=html, status_code=200)

View file

@ -0,0 +1,3 @@
bind = "127.0.0.1:8081"
workers = 1
worker_class = "uvicorn.workers.UvicornWorker"