diff --git a/Webhook.md b/Webhook.md new file mode 100644 index 0000000..540002b --- /dev/null +++ b/Webhook.md @@ -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": "ok", + "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 + } + } +} +``` +