Simple API server created to learn Python and FastAPI.
You need to have Python 3.6 or higher installed, along with pip
. Next, install fastapi
and uvicorn
.
pip install fastapi "uvicorn[standard]"
Note: standard version of uvicorn is needed to get some additional libraries that will be necessary.
Create a very simple server by setting up a main.py
file.
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
Run the server with:
uvicorn main:app --reload
Ready! Now check http://127.0.0.1:8000 at your browser.
A Swagger documentation has also been created automatically for your app. Check http://127.0.0.1:8000/docs.
Types can be added with the use of pydantic
.