EasyWebHook 1.0.1

dotnet add package EasyWebHook --version 1.0.1                
NuGet\Install-Package EasyWebHook -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasyWebHook" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasyWebHook --version 1.0.1                
#r "nuget: EasyWebHook, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EasyWebHook as a Cake Addin
#addin nuget:?package=EasyWebHook&version=1.0.1

// Install EasyWebHook as a Cake Tool
#tool nuget:?package=EasyWebHook&version=1.0.1                

EasyHook

An easy way to implement WebHooks

This project is an attempt to help our fellow developers to implement webhooks in their projects. The idea is to simply call instantiate the object and shoot a webhook to wherever you want to. This is a simple project that I came up with when I was tired and not thinking super straight, so I am sure you'll find issues, but if so, please contribute to the project! We want to make it better!

Note: The project currently accepts only POST HTTP Requests

Usage

To get started hooking everything, you need to include/install the package in your project, you can do that by running the following code in your Package Manager Console:

PM> Install-Package EasyWebHook

Note: You can get more information here

Once installed, you are ready to roll. You now need to instantiate some objects to have it working nicely.

Settings

You'll first need to set the settings of how your webhooks should work, you can do that by having an instance of EasyWebHookSettings, like this:

using Easy.Hook.Helpers;

EasyWebHookSettings hookSettings = new EasyWebHookSettings() 
{ 
  HttpClient = new HttpClient(), 
  UriWebhook = new Uri("https://httpbin.org/post") 
};

Note: You don't need to create a new HttpClient everytime, if you have one already instantiated, just use that one.

EasyWebHook

With the settings object created, we can now create an instance of EasyWebHook, like this:

using Easy.Hook;

EasyWebHook<T> easyHook = new EasyWebHook<T>(hookSettings);

Send a hook

Now that we have the EasyWebHookSettings and the EasyWebHook objects, we can trigger our webhooks! Here's how you can do that:

easyHook.WebHook.Send(webhookEvent);

Note: The Send Method returns a Task therefore, it is awaitable if needed. To have the response just do this:

var result = await easyHook.WebHook.Send(webhookEvent);

Example

using Easy.Hook;
using Easy.Hook.Helpers;
using HookConsole.Models;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace HookConsole
{
    public class Program
    {
        static async Task Main(string[] args)
        {
            EasyWebHookSettings hookSettings = new EasyWebHookSettings() { 
                HttpClient = new HttpClient(), 
                UriWebhook = new Uri("https://httpbin.org/post") 
            };
            EasyWebHook<WebhookEvent> easyHook = new EasyWebHook<WebhookEvent>(hookSettings);

            Person person = new Person() {
                Id = 556,
                FirstName = "Henrique", 
                LastName = "Tedeschi", 
                Gender = "Male", 
                DateOfBirth = DateTime.Parse("Jan 1, 1990") 
            };

            WebhookEvent webhookEvent = new WebhookEvent() { 
                UserInitiated = 1, 
                EventId = 10233, 
                Data = person 
            };

            var result = await easyHook.WebHook.Send(webhookEvent);
            // result looks like:
            // Success (bool) = true
            // Content (Newtonsoft.Json.Linq.JObject) = {{"args": { },"data": "{\"EventId\":10233,\"OccurredAt\":\"2021-08-17T21:03:28.8511005-06:00\",\"UserInitiated\":1,\"Data\":{\"Id\":556,\"FirstName\":\"Henrique\",\"LastName\":\"Tedeschi\",\"DateOfBirth\":\"1990-01-01T00:00:00\",\"Gender\":\"Male\"}}","files":{ },"form":{ },"headers":{ "Content-Length":"199","Host":"httpbin.org"},"json":{ "Data":{ "DateOfBirth":"1990-01-01T00:00:00","FirstName":"Henrique","Gender":"Male","Id":556,"LastName":"Tedeschi"},"EventId":10233,"OccurredAt":"2021-08-17T21:03:28.8511005-06:00","UserInitiated":1},"origin":"71.199.xx.xxx","url":"https://httpbin.org/post"}};
            // HttpResponseMessage (HttpResponseMessage) = {StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:{Date: Wed, 18 Aug 2021 03:09:23 GMTConnection: keep - aliveServer: gunicorn / 19.9.0Access - Control - Allow - Origin: *Access - Control - Allow - Credentials: trueContent - Type: application / jsonContent - Length: 794}}
            // ResponseDateTime (DateTime) = {8/17/2021 9:09:23 PM}

            Console.WriteLine("Hello World!");
        }
    }
}

Final Words

That's it! Hopefully by now you've managed to send your webhooks. Easy, isn't it? If you want to help me out, contribute to this project, and use it in your development. If you REALLY want to help me out, here's my Venmo so you can donate something, or you can also Sponsor me in GitHub.

Thank you!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 1,673 8/18/2021
1.0.0 269 8/18/2021

- Created project
- Working only with POST requests
- Added details to NuGet Package descriptions