-
-
Notifications
You must be signed in to change notification settings - Fork 209
Webhook
Stef Heyenrath edited this page Mar 9, 2021
·
4 revisions
It's also possible to define a Webhook 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.
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"));
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>",
"Headers": {
"Content-Type": "application/xml"
}
},
"Webhook": {
"Request": {
"Url": "https://any-endpoint.com",
"Method": "POST",
"Headers": {
"x": "x-value"
},
"Body": "ok - RequestPath used = {{request.path}}",
"UseTransformer": true
}
}
}
- 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