Skip to content

Instantly share code, notes, and snippets.

@Bachmann1234
Created July 26, 2022 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bachmann1234/7d365d3d6d11a7204e89a478794aa210 to your computer and use it in GitHub Desktop.
Save Bachmann1234/7d365d3d6d11a7204e89a478794aa210 to your computer and use it in GitHub Desktop.
Webhook dumper
from flask import Flask, request
import json
from pygments import highlight
from pygments.formatters.terminal256 import Terminal256Formatter
from pygments.lexers import get_lexer_by_name
app = Flask(__name__)
@app.route("/")
def healthcheck():
return "OK"
@app.route("/hook", methods=["POST"])
def dump_body():
print(_highlight(json.dumps(dict(request.headers), indent=4)))
print(_highlight(json.dumps(request.json, indent=4)))
return "OK"
def _highlight(json_data):
return highlight(
code=json_data,
lexer=get_lexer_by_name("json"),
formatter=Terminal256Formatter(style="solarized-dark"),
)
@Bachmann1234
Copy link
Author

 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
{
    "Host": "127.0.0.1:5000",
    "User-Agent": "curl/7.79.1",
    "Accept": "*/*",
    "Content-Type": "application/json",
    "Content-Length": "20"
}

{
    "cat": "dog"
}

127.0.0.1 - - [26/Jul/2022 10:43:43] "POST /hook HTTP/1.1" 200 -```

@Bachmann1234
Copy link
Author

Screen Shot 2022-07-26 at 10 44 25 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment