/flask-pymongo-overview

Example Script - Flask+PyMongo for RESTful API

Primary LanguagePythonOtherNOASSERTION

Designing RESTful API with Python-Flask and MongoDB

This example project demonstrate how to design RESTful API with Python-Flask and MongoDB. This overview is a part of training program at Fusemachines.

Assets

  1. Presentation Slides|PDF
  2. Presentation Document

Installation

Cloning the repository
# Get the project code
git clone https://github.com/Sushil-Thapa/flask-pymongo-overview.git

NOTE: Please use virtual environment to keep all the project's dependencies isolated from other projects.

Create your local environment
virtualenv -p python3 .venv
source .venv/bin/activate
Install dependencies
pip install -r requirements.txt
Start MongoDB Server

If you're using Linux, you could use the following to start the server if you already haven't.

sudo service mongod start

Config the application

Change the MONGO_DBNAME in the config file according to the database name you are using.

Start the application

python run.py
or
gunicorn -b :5000 -w 2 -t 120 app:app
or
FLASK_APP=app.py flask run

Once the application is started, go to localhost on Postman and explore the APIs. Sample postman collection schema (version 2.1) is uploaded here.

Using Docker container

  • Build container docker build -t my_docker:latest .

  • Run container docker run -ti -p 8080:8080 my_docker:latest