In this article, I will show you the basics of the Webhook mechanism that uses a publish-subscribe pattern in the ASP.NET CORE 3.1 project.

What is Webhook

Webhooks are user-defined HTTP callbacks. They are usually triggered by some events, such as pushing code to a repository or a comment being posted to a blog. When that event occurs, the source site makes an HTTP request to the URL configured for the Webhook. Users can configure them to cause events on one site to invoke behavior on another.

(https://en.wikipedia.org/wiki/Webhook)

We have implemented a Webhook mechanism that uses a publish-subscribe pattern to our ASP.NET Boilerplate and ASP.NET ZERO projects. Users can subscribe to a Webhook event(s) (for example User.Created , Notification.NewNotification etc…) then when that event occurs application publishes a Webhook(s) to subscribed endpoints.

Implementation

Note:_ In this article, I will not show any basic CRUD operation code. I will just share the parts that I think are important. If you want all codes and more you can check ASP.NET Boilerplate github page._

**WebhookSubscription: **An entity that we will store Webhook subscriptions.

The important thing is the subscription’s secret. You should set it when you create a Webhook subscription and never change it. (Unless your custom logic contains something like change Webhook secret)

#webhooks #aspnetcore #net-core

ASP.NET CORE 3.1 Webhook Implementation Using Pub/Sub Pattern
60.85 GEEK