简体   繁体   中英

Flask With Swagger Log input and output

I am using Flask with swagger to create an apis system. Which has json as entry and exit points.

from flask import Flask
app = Flask(__name__)
Swagger(app)

@app.route('/some_url', methods=['POST'])
def get_output():
    return json.dumps({"status":"Success"})

The Input for above is eg

{"username":username,"password":password,}

Like Above I have several other methods either GET or POST.

Is it possible to log the entry exit points Eg as in Above Example I should be able to log following

  • {"username":username,"password":password,} as entry point
  • {"status":success} as exit point.

As well if some error should be able to log it. Looking forward for right way of doing same.

There are some decorators can help you to achieve that.

You can log request.path , request.head , request.args , request.form , request.data in @app.before_request .

You can log response.data in @app.after_request .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM