The most common format for the payloads of Webhooks is the JSON format, but it is possible to use also the XML format, as long as the receiver is able to understand it. The framework provides a mechanism to serialize the payloads of the messages sent to the receivers.
The framework provides a set of default implementation of the serializers
Type | Library | Description |
---|---|---|
SystemTextWebhookJsonSerializer | Deveel.Webhooks | An implementation that uses the System.Text.Json serialization functions (recommended) |
NewtonsoftWebhookJsonSerializer | Deveel.Webhooks.NewtonsoftJson | Implements the webhook serialization by using the Newtonsoft.Json serializers |
SystemWebhookXmlSerializer | Deveel.Webhooks | Serializes webhooks to XML using the System.Xml native functions |
When initializing the sender, a default serializer for each format is added to the service, but it is possible to add custom ones through the call to .UseJsonSerializer<TSerializer>()
or .UseXmlSerializer<TSerializer>()
of the service builder.
using System;
using Microsoft.Extensions.Configuration;
using Deveel.Webhooks;
namespace Example {
public class Startup {
public Startup(IConfiguration config) {
Configuration = config;
}
public IConfiguration Configuration { get; }
public void Configure(IServiceCollection services) {
// ... add any other service you need ...
// this call adds the basic services for sending of webhooks
services.AddWebhookSender<MyWebook>(webhooks => {
webhooks.UseJsonSerializer<MyJsonSerializer>();
webhooks.UseXmlSerializer<MyXmlSerializer>();
});
}
}
}