Skip to content

Commit 793e296

Browse files
committed
doc: updated readmes
1 parent c8409b0 commit 793e296

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
### Generating HttpContent for a Webhook
77
```csharp
8-
var testEntity = new TestEntity
8+
var myEntity = new MyEntity
99
{
1010
Id = 1,
1111
Name = "Test Entity",
@@ -16,10 +16,39 @@ var webhook = new StandardWebhook(WEBHOOK_SIGNING_KEY);
1616

1717
var sendingTime = DateTimeOffset.UtcNow;
1818

19-
var webhookContent = webhook.MakeHttpContent(testEntity, DEFAULT_MSG_ID, sendingTime);
19+
var webhookContent = webhook.MakeHttpContent(myEntity, DEFAULT_MSG_ID, sendingTime);
20+
```
21+
22+
### Verifying a Webhook signature
23+
```csharp
24+
// Assumes messageBody contains string representation of message content
25+
// and request is an HttpRequest with the Standard Webhooks headers set
2026
27+
var webhook = new StandardWebhook(WEBHOOK_SIGNING_KEY);
28+
29+
// Throws WebhookVerificationException if verification fails
30+
webhook.Verify(messageBody, request.Headers);
2131
```
2232

33+
### Factory Pattern
34+
The library provides `IStandardWebhookFactory` and its implementation `StandardWebhookFactory`
35+
which are intended for use in ASP.NET DI scenarios. Usage:
36+
```csharp
37+
// In Program.cs, or wherever services are configured. Optionally WebhookConfigurationOptions can be
38+
// provided as a second parameter to configure which header names to use.
39+
40+
services.AddSingleton<IStandardWebhookFactory>(sp =>
41+
new StandardWebhookFactory(WEBHOOK_SIGNING_KEY));
42+
43+
// In method, add IStandardWebhookFactory as an injected parameter and then:
44+
var webhook = webhookFactory.CreateWebhook();
45+
```
46+
47+
### Standard Configurations
48+
Two standard `WebhookConfigurationOptions` configurations are provided as static instances, `WebhookConfigurationOptions.StandardWebhooks` and
49+
`WebhookConfigurationOptions.Svix`, the former for the HTTP headers as described in the Standard Webhooks specification and
50+
the latter for the headers used by Svix. The default configuration if no options are supplied is `WebhookConfigurationOptions.StandardWebhooks`.
51+
2352
## Acknowledgements
2453

2554
This project leverages the work of the **Standard Webhooks** project, published on Github in the [standard-webhooks](https://github.com/standard-webhooks/standard-webhooks) repository.

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<ItemGroup>
2020
<None Include="$(SolutionDir)LICENSE.md" Pack="true" PackagePath="" />
21-
<None Include="$(SolutionDir)README.md" Pack="true" PackagePath="" />
21+
<None Include="$(SolutionDir)src\StandardWebhooks\README.md" Pack="true" PackagePath="" />
2222
</ItemGroup>
2323

2424
</Project>

src/StandardWebhooks/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
# Standard Webhooks
2-
## TBD
1+
# StandardWebhooks
32

3+
`StandardWebhooks` is an implementation of the [Standard Webhooks specification](https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md)
4+
initiated by Svix and supported by other industry participants including Zapier, Twilio, ngrok and Kong.
5+
6+
See the repo on [GitHub](https://github.com/codefactors/StandardWebhooks) for more information and examples.

0 commit comments

Comments
 (0)