Skip to content

Instantly share code, notes, and snippets.

@i5okie
Created November 19, 2019 18:52
Show Gist options
  • Save i5okie/0e71599b5f6604b3dd584b4a2d4aae32 to your computer and use it in GitHub Desktop.
Save i5okie/0e71599b5f6604b3dd584b4a2d4aae32 to your computer and use it in GitHub Desktop.
python webhook echo server with coloured formatted output
import json, ast
from flask import Flask, request, abort
from pygments import highlight, lexers, formatters
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
if request.method == 'POST':
formatted_json = json.dumps(request.json, indent=2, sort_keys=True)
print(request.headers)
print(highlight(unicode(formatted_json, 'UTF-8'), lexers.JsonLexer(), formatters.TerminalFormatter()))
return '', 200
else:
abort(400)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment