0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Webhookを自分で実装してみる

Posted at

趣旨

サーバーを複数運用していたらサーバー間でのWebhook通信も必要になる瞬間が来るんじゃないかと思って先に調べておきました。
Webhook自体が単なる HTTP リクエストなので割と簡単にできるみたいだったので、共有しておきます。

準備

外部サーバーのエンドポイントを準備する: Webhook データを受け取るためのエンドポイントを外部サーバー上に準備します。このエンドポイントは、HTTP リクエストを受け取り、適切に処理するように構成されている必要があります。

サーバー上でスクリプトを作成する: 外部のエンドポイントに HTTP リクエストを送信する Python スクリプトを作成します。このスクリプトでは、requests ライブラリなどを使用して HTTP リクエストを行うことができます。

スケジュールされたタスクを設定する: 必要に応じて、サーバーのスケジュールされたタスク機能を使用して、スクリプトが定期的に実行されるように設定します。これにより、定期的にデータを送信する Webhook を実装できます。

サンプルコード

import requests

url = 'http://example.com/webhook-endpoint'

data = {'key': 'value'}

response = requests.post(url, json=data)

print(response.text)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?