Skip to content

Production-ready FastAPI Mock Server for REST API and Websocket Testing

Notifications You must be signed in to change notification settings

arvin1408/fastapi-mock-server

Repository files navigation

FastAPI Mock Server

Features

  • Async SQLAlchemy session
  • Custom user class
  • Dependencies for specific permissions
  • Celery
  • Dockerize(Hot reload)
  • Event dispatcher
  • Cache

Run with Docker Compose

Install

Tested on Ubuntu 22.04. Check here for other platforms.

sudo apt-get update
sudo apt-get install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
sudo groupadd docker
sudo usermod -aG docker $USER

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version

Run

docker-compose up --build

Test endpoints

REST API

Sample login request after creating user

curl -X 'POST' \
  'http://localhost:8000/api/v1/user/login' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "email": "user@example.com",
  "password": "password"
}'

Sample login response

{
    "token": "eyJhbGciOi...",
    "refresh_token": "eyJhbGci..."
}

Websocket

  • Connect route: ws://localhost:8000/api/v1/ws/connect

Websocket connection with Bearer token provided Test screenshot

About

Production-ready FastAPI Mock Server for REST API and Websocket Testing

Resources

Stars

Watchers

Forks