Python API: Flask-RESTfull + Docker + MongoDB

Alvaro paco
Nov 13, 2018 · 2 min read



Main Files

# -*- coding: utf-8 -*-
import sys

from flask import Flask, jsonify, url_for, redirect, request, Blueprint
from flask_restful import Api, Resource
from urllib import quote_plus, quote

from resources.arrange import Arrange
from import Room
from common.logger import Logger
from common.mongoDB import MongoDb

def routes(api, db):
api.add_resource(Index, "/v1", endpoint="index")
api.add_resource(Arrange, "/v1/arrange", "/v1/arrange/<string:id>",
endpoint="arrange", resource_class_kwargs={'db': db})
api.add_resource(Room, "/v1/room", "/v1/room/<string:id>", endpoint="room",
resource_class_kwargs={'db': db})

def main(host, port, debug):

# app = application(host, port, debug)
#Logger(app), port, debug)

class Index(Resource):
def get(self):
return {"response": "health"}

# initialization of Flask Application
app = Flask(__name__)
app.register_blueprint(Blueprint('api', __name__))
mongo = MongoDb(app)
db = mongo.getDb()
routes(Api(app), db)

if __name__ == "__main__":
Alvaro paco

Written by

IT Software Engineer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade