chg: [server] move to flask-restx + OpenAPI documentation exposed

main
Alexandre Dulaunoy 2021-05-22 12:04:05 +02:00
parent 8862cfcfce
commit 8f8af42b1e
No known key found for this signature in database
GPG Key ID: 09E2CD4944E6CBCD
2 changed files with 18 additions and 10 deletions

View File

@ -1,21 +1,28 @@
version = "0.1" version = "0.1"
from flask import Flask from flask import Flask
from flask_restx import Resource, Api
app = Flask(__name__) 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 uuid
import inspect import inspect
import redis 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') r = redis.Redis(host='127.0.0.1', port='3033')
def generateUUID(): @api.route('/info')
genuuid = uuid.uuid4() class info(Resource):
k = "stats:f:{}".format(inspect.stack()[0][3].lower()) def get(self):
r.incr(k, 1) return "CyCAT backend {}".format(version)
return "{}".format(genuuid)
@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__': if __name__ == '__main__':
app.run() app.run()

View File

@ -1,2 +1,3 @@
flask flask
redis redis
flask_restplus