Skip to content

Latest commit

 

History

History
103 lines (60 loc) · 2.38 KB

README.md

File metadata and controls

103 lines (60 loc) · 2.38 KB

FastAPI + MongoDB

A simple starter for building RESTful APIs with FastAPI and MongoDB.

Features

  • Python FastAPI backend.
  • MongoDB database.
  • Authentication
  • Deployment

How To Use

Clone this repository and make a virtual environment in it. Install the modules listed in the requirements.txt file:

pip3 install -r requirements.txt

To run the starter:

First, set your PYTHONPATH:

export PYTHONPATH=$PWD

Next:

python app/main.py

You also need to start your mongodb instance.

The starter listens on port 8000 on address 0.0.0.0.

FastAPI-MongoDB starter

Deploying to Vercel

Currently, the vercel build fails when running requests to MongoDB through the async driver. The next section shows how to deploy to Heroku.

To deploy to vercel, make sure the vercel CLI tool is installed and run the command in the base directory:

vercel 

The above deploys to development, to deploy it into production, run:

vercel --prod

Ensure you add the environment variable MONGO_DETAILS in vercel.

Deploying to Heroku

To deploy to Heroku, connect your repository to the Heroku application and deploy the branch master. This template has been deployed to Heroku and you can view it here: FastAPI Mongo

Ensure you add the environment variable MONGO_DETAILS in your application's settings.

Dockerising

To build a docker image for this boilerplate, create a duplicate .env file but with name env. Next, build an image:

docker build -t fastapi-mongo .

The command above builds an image that can be deployed. To run the image in a container:

docker run --env-file env -d --name fastapi-mongo -p 80:80 fastapi-mongo:latest

Contributing ?

Fork the repo, make changes and send a PR. We'll review it together!

TODOS

  • Add a simple bash script file that runs the installation process.

  • Fix the UPDATE part of the CRUD operation

  • Add Authentication

  • Add Dockerfile

  • Vercel configuration file

  • Deploying to Heroku

  • Write a concise README

  • Format code. I'm new to FastAPI so I'll be working towards best practices.

License

This project is licensed under the terms of MIT license.