TIL

Today I Learned. 知ったこと、学んだことを書いていく

POSTリクエストの処理 - Bottle

POSTリクエストの処理

BottleでPOSTのリクエストを処理する場合、@route("/example", method="POST")@post("/example")とすればよい

以下のようなwebhook.pyというソースコードがあったとする

from bottle import route, run

@route('/webhook', method="POST")
def webhook():
  print("webhook!")

run(host='localhost', port=3000, debug=True)

実行する

$ python webhook.py

http:/localhost:3000/webhookに対してPOST送信すると

webhook!
127.0.0.1 - - [16/Aug/2017 21:27:55] "POST /webhook HTTP/1.1" 200 0

といったように出力される!

参考文献

Tutorial — Bottle 0.13-dev documentation