Last active
January 29, 2022 11:51
-
-
Save cobaltgit/98dd64313a7ed942ed928c1df508a6d5 to your computer and use it in GitHub Desktop.
Receive webhooks using Sanic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sanic import Sanic | |
from sanic.response import json | |
from sanic.exceptions import InvalidUsage | |
app = Sanic(__name__) | |
def webhook_actions(): | |
"""Actions to perform when webhook receives POST request""" | |
pass | |
@app.post("/") | |
async def webhook(request): | |
if request.headers.get("Content-Type") == "application/json": | |
webhook_actions() | |
return json(request.json) | |
else: | |
raise InvalidUsage(f"Invalid content type - expected application/json, got {request.headers["Content-Type"]}) | |
if __name__ == "__main__": | |
app.run(port=5000, host="0.0.0.0") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment