Creating an API with FastAPI

This guide will walk through the process of developing a FASTAPI and deploying to an AWS EC2 instance with a custom domain and SSL/HTTPS certification.

Create Virtual Environment

mkdir fastapi
cd fastapi
python3 -m venv env
source env/bin/activate

Create a FASTAPI project

pip install fastapi uvicorn

Create main.py

from fastapi import FastAPI

app = FastAPI()

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

Launch API

# Launch Uvicorn and load main.py app
sudo /home/ubuntu/fastapi/env/bin/uvicorn 
sudo /home/ubuntu/fastapi/main:app --reload

Visit Documentation

https://fastapi.tiangolo.com/tutorial/

Creating a FastAPI Ubuntu service

[Optional] Create a Monitor with Monit

Websockets

Last updated