My First REST API with Python and Flask-RESTPlus

With few or no explanations, on Debian 10:

sudo apt install nginx python3-venv curl
mkdir resttest
cd resttest
python3 -m venv venv
. venv/bin/activate
pip install wheel
pip install flask flask-restplus gunicorn

The actual API app, in ~/resttest/

from flask import Flask
from flask_restplus import Api, Resource

app = Flask(__name__)
api = Api(app)

class Test(Resource):
    def get(self, id):
        return {"result":"get {} ok".format(id)}, 200

# For testing without the external runner:
if __name__ == "__main__":"")


from resttest import app

if __name__ == "__main__":


Description=My REST test app, run by Gunicorn

ExecStart=/home/markku/resttest/venv/bin/gunicorn --workers 3 --bind unix:resttest.sock --umask 007 wsgi:app



server {
    listen 80;
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/markku/resttest/resttest.sock;

Final setup steps:

sudo ln -s /etc/nginx/sites-available/resttest /etc/nginx/sites-enabled
sudo nginx -t
sudo systemctl start resttest
sudo systemctl enable resttest
sudo systemctl restart nginx

Testing results:

$ curl
{"result": "get 555 ok"}

Also note that the Swagger UI is automatically accessible in

Some future considerations:

  • TLS encryption (= reconfiguring NGINX)
  • Authentication for the API
  • Disabling/customizing the Swagger UI


The post was inspired by: How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 18.04 (

Updated: October 12, 2019 — 18:11

Leave a Reply