mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-05-05 14:43:21 +02:00
Created Webhook (markdown)
74
Webhook.md
Normal file
74
Webhook.md
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
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](https://github.com/WireMock-Net/WireMock.Net/wiki/Response-Templating) is also supported for the `request` and `response` objects.
|
||||||
|
|
||||||
|
# Examples
|
||||||
|
### C#
|
||||||
|
This is configurable in code:
|
||||||
|
``` c#
|
||||||
|
// 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:
|
||||||
|
``` json
|
||||||
|
{
|
||||||
|
"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": "http://{{wm_hostname}}/post",
|
||||||
|
"Method": "POST",
|
||||||
|
"Headers": {
|
||||||
|
"x": "x-value"
|
||||||
|
},
|
||||||
|
"Body": "ok - RequestPath used = {{request.path}}",
|
||||||
|
"UseTransformer": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Reference in New Issue
Block a user