From 8f8af42b1ecf9fe6a2d7f0ffcd2ecf29b1be6f31 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sat, 22 May 2021 12:04:05 +0200 Subject: [PATCH] chg: [server] move to flask-restx + OpenAPI documentation exposed --- backend/bin/server.py | 27 +++++++++++++++++---------- backend/requirements.txt | 1 + 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/backend/bin/server.py b/backend/bin/server.py index d6cecb1..29e1841 100644 --- a/backend/bin/server.py +++ b/backend/bin/server.py @@ -1,21 +1,28 @@ version = "0.1" from flask import Flask +from flask_restx import Resource, Api + app = Flask(__name__) +app.url_map.strict_slashes = False +api = Api(app, version=version, title='CyCAT.org API', description='CyberSecurity catalog API services', doc='/doc/') import uuid import inspect import redis -r = redis.Redis(host='127.0.0.1', port='3033') -@app.route('/info') -def info(): - return "CyCAT backend {}".format(version) -@app.route('/generate/uuid') -def generateUUID(): - genuuid = uuid.uuid4() - k = "stats:f:{}".format(inspect.stack()[0][3].lower()) - r.incr(k, 1) - return "{}".format(genuuid) +r = redis.Redis(host='127.0.0.1', port='3033') +@api.route('/info') +class info(Resource): + def get(self): + return "CyCAT backend {}".format(version) + +@api.route('/generate/uuid') +class generateUUID(Resource): + def get(self): + genuuid = uuid.uuid4() + k = "stats:f:{}".format(inspect.stack()[0][3].lower()) + r.incr(k, 1) + return "{}".format(genuuid) if __name__ == '__main__': app.run() diff --git a/backend/requirements.txt b/backend/requirements.txt index 1a5dc97..039899b 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,2 +1,3 @@ flask redis +flask_restplus