Getting started with Microsoft ASP.NET WebHooks Preview
Background
There was an announcement for 'Microsoft ASP.NET WebHooks Preview' on September 04, 2015, where Henrik F Nielsen announced the release of 'Microsoft ASP.NET WebHooks Preview' as a new member of ASP.NET family.
For more information regarding this announcement, please refer to:
Introduction
In this article, we will discuss about ASP.NET WebHook-Preview.
Through-out this article, we will discuss about WebHooks, implementation with very first preview release of 'Microsoft ASP.NET WebHooks Preview'.
Purpose
Currently, 'Microsoft ASP.NET WebHooks Preview' is not finalized for release and in the stage where developer can try to use the magic of WebHooks in their code. In this article we will discuss more about this new member of ASP.NET family and try to understand the power of WebHooks using a simple program.
Prerequisite
There is no such major things required to start with WebHooks, we just need to know:
- Basics of Services (Web APIs etc.)
- Visual Studio 2013 or later
- Basic knowledge of ASP.NET
What is WebHook?
To understand, first think about a scenario, where we need to perform some action on the output/result of an existing action.
We can also consider callback in C#, where we are performing few custom actions on results. Its not wrong if I say Program-A automatically trigered with an input of output from ProgramA.
In simple words, we can say WebHooks are program/methods/functions/piece-of-code, which modified the actual behavior of a Web page, application, Resource etc.
The interesting thing is that these program/triggers can be/ can not be a part of actual WebSite, Web Application, where Program-A belongs.
The term Web reminds us to HTTP. So, we can say that Webhooks are nothing but just HTTP callback moreover these are user-defined HTTP Callback. In year 2007, term WebHook came to announce, when Jeff Lindsay take it from Hook.
“WebHook is a lightweight HTTP pattern providing a simple pub/sub model for wiring together Web APIs and SaaS services. When an event happens in a service, a notification is sent in the form of an HTTP POST request to registered subscribers. The POST request contains information about the event which makes it possible for the receiver to act accordingly.”
Real time examples of WebHooks
We have lot of examples in our day-to-day life, might be we missed these:
- Checking-in/pushing a code into repository.
- Trigging deployment build.
- Posting comments on your favorite blogs.
- Post Trackback.
More Real time examples of WebHooks
Think a scenario of a factory, which uses a crude oil as a raw material. There is a huge consumption of this oil in the factory on daily basis. They have three mark to maintain the oil storage/stock level in the factory.
- Red for lowest stock and denotes stop usage.
- Yellow for in stock and denotes can use.
- Green for lower stock and denotes order to purchase more.
Think a scenario, where factory workers/store-keepers or field-supervisors are maintaining numerous records for the stock of this oil. You can think how much complex this in real scenario?
What is the problem here?
In normal scenario, where the consumption of this crude oil is not so much and can easily be maintained by manual interventions/activities. Unfortunately, in our case it is not so much simpler to take a bite of bread with Tea.
Here, we need skilled workers to maintain records and set the indicators accordingly so, related action can be taken. Think, how much time, cost and manpower would be required in this scenario. Isn't it good to automate it?
What is the solution then?
There might be many solutions we can think over. But here are the possible solutions:
- Make this process automate
- Write a short program/app to maintain the difference stock level
- Automate process so, related person get notified for action(s)
In all of above solutions, we need to trigger some action on the output of a particular action or talk. Isn't it relate to WebHook?
In my personal opinion, I should suggest to do something like this:
- Write a program/app, which maintain the stock time-to-time (on/when action required)
- And notify the Panel-section to alarm Red, Yellow or Green indicators
With this solution as soon as there is any addition/subtraction in the quantity of Crude-oil our program notify our Stock-Panel (which is nothing but similar to Traffic control light) and it trigers accordingly.
What is pub/sub model?
This is nothing but a publish-scubscribe pattern/model - a messaging pattern. We can assume this as a message-queue paradigm too. We are not getting in more depth for pub/sub model, please refer to below link for further details:
Applications/Projects provide WebHook
Term WebHook is not new (already discussed above it is coined in 2007) in the world of Web. There are lot of applications already provide, support WebHook, followings are fewer name:
- Dropbox
- GitHub
- Trello
- Zendesk
- PayPal
- SalesForce
- Wordpress
Overview of ASP.NET WebHook Preview
There is nothing much change in Microsoft ASP.NET WebHook Preview, it maintains the same publish-subscribe model/pattern as we discussed above.
In other words, we can say that ASP.NET WebHook does both send and receive Hook as/within ASP.NET application/program. It has two sides:
- Sending
- Receiving
How to start working with ASP.NET WebHook Preview
Follow these simple step(s)
- Choose your package app for which you want to use WebHooks viz. GitHub, Trello, DropBox etc.
- Install from Preview NuGet eg. GitHub
- Alternatively, you can visit GitHub