mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 13:00:33 +01:00
Page:
Webhook
Pages
Admin API Reference
Compatibility WireMock.org
Conflict on Microsoft.CodeAnalysis.CSharp
Cors
Could not load file or assembly RestEase
Development Information
Faults
FluentAssertions
Home
KestrelServerOptions
Mapping
MimeKit and MimeKitLite
MyGet preview versions
Pact
Proxying
References
RegexExtended
Request Matcher FormUrlEncodedMatcher
Request Matchers
Request Matching CSharpCode
Request Matching GraphQLMatcher
Request Matching JsonMatcher
Request Matching JsonPartialMatcher
Request Matching JsonPartialWildcardMatcher
Request Matching JsonPathMatcher
Request Matching MimePartMatcher
Request Matching ProtoBuf
Request Matching Tips
Request Matching
Response Templating
Scenarios and States
Settings
Stubbing
Using HTTPS (SSL)
Using WireMock in UnitTests
Using WireMock.Net.Aspire
Using WireMock.Net.Testcontainers
Webhook
What Is WireMock.Net
WireMock as a (Azure) Web App
WireMock as a Windows Service
WireMock as a standalone process
WireMock as dotnet tool
WireMock commandline parameters
WireMock.Org
Xamarin Could not load file or assembly
Clone
4
Webhook
Stef Heyenrath edited this page 2021-05-19 12:56:47 +02:00
It's also possible to define a Webhook (or multiple Webhooks) for a mapping.
With this you can send request to a specific URL after serving mocked response to a request.
Note that transformations/templating is also supported for the request and response objects.
Examples
C#
This is configurable in code:
// Option 1
var server = WireMockServer.Start();
server.Given(Request.Create().UsingPost())
.WithWebhook(new Webhook
{
Request = new WebhookRequest
{
Url = "https://any-endpoint.com",
Method = "post",
BodyData = new BodyData
{
BodyAsString = "OK !",
DetectedBodyType = BodyType.String
}
}
})
.RespondWith(Response.Create().WithBody("a-response"));
// Option 2
var server2 = WireMockServer.Start();
server2.Given(Request.Create().UsingPost())
.WithWebhook("https://any-endpoint.com", "post", null, "OK !", true, TransformerType.Handlebars)
.RespondWith(Response.Create().WithBody("a-response"));
JSON
Or via posting this mapping:
{
"Guid": "755384f9-2252-433d-ae8b-445b9f1cc729",
"Priority": 0,
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/wh"
}
]
},
"Methods": [
"POST"
]
},
"Response": {
"Body": "<xml>ok</xml>",
"StatusCode": 201,
"Headers": {
"Content-Type": "application/xml"
}
},
"Webhook": {
"Request": {
"Url": "https://any-endpoint.com",
"Method": "POST",
"Headers": {
"x": "x-value"
},
"Body": "ok - RequestPath used = {{request.path}}, RESP = {{response.StatusCode}}",
"UseTransformer": true
}
}
}
Pages
- Home
- What is WireMock.Net
- WireMock.Org
- References
- Settings
- Admin REST API
- Proxying
- Stubbing
- Webhook
- Request Matching
- Response Templating
- Unit Testing
- Using WireMock
- Advanced
- Errors