Minimal FastAPI webserver example

This is the minimal FastAPI webserver

minimal_fastapi_app.py
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def read_root():
    return {"message": "Hello, World!"}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)

Run this script and then visit http://localhost:8000 in your browser to see:

example.json
{"message": "Hello, World!"}

Check out similar posts by category: FastAPI, Python