FastAPI stands on the shoulders of giants:
Create a virtual environment.
$ py -3 -m venv your_env_name
Invoke the virtual environment.
$ your_env_name\Scripts\activate.bat
Download all packages found in the requirements.txt file
$ pip install -r requirements.txt
Make a .env file (use .env.sample as an example). Fill in the values.
$ touch .env
Run the server with:
$ uvicorn app.main:app --reload
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [28720]
INFO: Started server process [28722]
INFO: Waiting for application startup.
INFO: Application startup complete.About the command uvicorn main:app --reload...
The command uvicorn app.main:app refers to:
main: the filemain.py(the Python "module") inside the directoryapp.app: the object created inside ofmain.pywith the lineapp = FastAPI().--reload: make the server restart after code changes. Only do this for development.
Open your browser at http://127.0.0.1:8000.
You will see the JSON response as:
{"message": "Welcome to my post application"}Now go to http://127.0.0.1:8000/docs.
You will see the automatic interactive API documentation (provided by Swagger UI):
And now, go to http://127.0.0.1:8000/redoc.
You will see the alternative automatic documentation (provided by ReDoc):