Introduction To FastAPI

Learn how to setup FasAPI in your system

Featured image

FastAPI

FastAPI is a Web framework for developing RESTful APIs in Python. FastAPI is based on Pydantic and type hints to validate, serialize, and deserialize data, and automatically auto-generate OpenAPI documents.

Checkout This YouTube Video For more details:

Install Python Libraries

Learn to setup Virtual Env: Link

Conda Environment

Method 1 - Anaconda Navigator

Anaconda Navigator

This will create conda environment with the name backend with Python 3.8 version. You can change it according to your need.

Method 2 - Anaconda Command Terminal

conda create -n backend python=3.10

This will create virtual environment with the name backend with Python 3.10 version. You can change it according to your need.

Setup FastAPI

https://anaconda.org/conda-forge/fastapi

https://anaconda.org/conda-forge/uvicorn-standard

conda activate backend
conda install -c conda-forge fastapi
conda install -c conda-forge uvicorn-standard

Pip Environment

mkvirtualenv backend
workon backend

pip3 install fastapi
pip3 install "uvicorn[standard]"

Basic Backend Code

Create a file main.py

from fastapi import FastAPI

app = FastAPI()


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

Run Using:

uvicorn main:app --reload
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

You will be able to see the output at 127.0.0.1:8000

Swagger Doc

http://127.0.0.1:8000/docs

Redoc

http://127.0.0.1:8000/redoc