Starting FastAPI
To start a FastAPI app you will need to set up first a path operation
# Import FastAPI framework
from fastapi import FastAPI
# Set up the App
app = FastAPI()
# Set up the path operation
@app.get("/")
async def root():
return {"message": "Hello World"}
Then you will have to run the uvicorn webserver by using the file name followed by the app name in said file
uvicorn main:app
# If you get an error that uvicorn is not valid use:
python -m uvicorn main:app --reload
This should return the information that the browser is running on local host
INFO: Started server process [21240]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Now you can access the API in the browser and see the message
Last updated