Switch branches/tags
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
.swagger-codegen
swagger_server
.dockerignore
.swagger-codegen-ignore
.travis.yml
Dockerfile
README.md
git_push.sh
requirements.txt
setup.py
test-requirements.txt
tox.ini

README.md

news feed micro-service in python

Overview

This edition of a rudimentary news feed micro-service was written in python 3 on flask.

You can read more about this project in this blog on Python Flask vs Node.js.

The controllers and the models are generated by the swagger-codegen project which uses the Connexion library on top of Flask.

Usage

Here is how to build and run this service.

Installation

Here are some installation steps that you will need to perform. This assumes that you already have python 3 installed. You will need to install the MySql Connector for Python which was at version 2.0.4 when I developed this.

pip3 install -r requirements.txt
wget http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.zip#md5=3df394d89300db95163f17c843ef49df
unzip mysql-connector-python-2.0.4.zip 
cd mysql-connector-python-2.0.4
sudo /usr/local/bin/python3.6 setup.py install

Running the Service

To run the service, please execute the following from the root directory of this application. Be sure to adjust the configuration file setting appropriately.

export APP_CONFIG=/home/glenn/git/clojure-news-feed/server/feed5/swagger_server/config-local.cfg
python3 -m swagger_server

Testing the Service

Here are illustrative curl calls to test out the service. This assumes that Joe's id is 1 and Betty's id is 2.

curl -H "Content-Type: application/json" -d '{"name":"joe flask"}' http://localhost:8080/participant/new
curl -H "Content-Type: application/json" -d '{"name":"betty python"}' http://localhost:8080/participant/new
curl -H "Content-Type: application/json" -d '{"from":1,"to":2}' http://localhost:8080/friends/new
curl -H "Content-Type: application/json" -d '{"from":1,"subject":"testing flask","story":"python on flask is cool"}' http://localhost:8080/outbound/new
curl http://localhost:8080/inbound/2

To see the API documentation, open http://localhost:8080/ui/ in your favorite web browser.

To launch the integration tests, use tox:

sudo pip install tox
tox

Running with Docker

To run the server on a Docker container, please execute the following from the root directory:

# building the image
docker build -t swagger_server .

# starting up a container
docker run -p 8080:8080 swagger_server