Webhook with generic url, body and custom header values #456

Closed
opened 2025-12-29 15:24:11 +01:00 by adam · 5 comments
Owner

Originally created by @ouell on GitHub (Sep 30, 2022).

In the java version we have:

wm.stubFor(post(urlPathEqualTo("/something-async"))
      .willReturn(ok())
      .withPostServeAction("webhook", webhook()
          .withMethod("{{jsonPath originalRequest.body '$.callbackMethod'}}")
          .withUrl("{{jsonPath originalRequest.body '$.callbackUrl'}}"))
  );

I pass the url with some parts of the request and the body.

In .net i try make something like:

server.Given(Request.Create().WithPath("/callback/pagar/").UsingPost()
    .WithParam("bandeira")
    .WithParam("paymentid"))
    .WithWebhook(new Webhook
    {
        Request = new WebhookRequest
        {
            Url = "http://localhost:5000/" + "{{request.Query.bandeira}}" + "/" + "{{request.Query.paymentid}}",
            Method = "post",
            Headers = new Dictionary<string, WireMockList<string>>()
            {
                {
                    "x-origem", new WireMockList<string>("customheader")
                }
            },
            BodyData = new BodyData
            {
                DetectedBodyType = BodyType.Json,
                BodyAsJson = CreateCallbackPagamento.CreateCallback("{{request.Query.paymentid}}")
            },
            UseTransformer = true
        }
    })
    .RespondWith(Response.Create()
                        .WithStatusCode(200)
                        .WithHeader("Content-Type", "application/json"));

I don't know how to pass the custom header.
And dosen't transform the fields in url

Originally created by @ouell on GitHub (Sep 30, 2022). In the java version we have: ```java wm.stubFor(post(urlPathEqualTo("/something-async")) .willReturn(ok()) .withPostServeAction("webhook", webhook() .withMethod("{{jsonPath originalRequest.body '$.callbackMethod'}}") .withUrl("{{jsonPath originalRequest.body '$.callbackUrl'}}")) ); ``` I pass the url with some parts of the request and the body. In .net i try make something like: ```java server.Given(Request.Create().WithPath("/callback/pagar/").UsingPost() .WithParam("bandeira") .WithParam("paymentid")) .WithWebhook(new Webhook { Request = new WebhookRequest { Url = "http://localhost:5000/" + "{{request.Query.bandeira}}" + "/" + "{{request.Query.paymentid}}", Method = "post", Headers = new Dictionary<string, WireMockList<string>>() { { "x-origem", new WireMockList<string>("customheader") } }, BodyData = new BodyData { DetectedBodyType = BodyType.Json, BodyAsJson = CreateCallbackPagamento.CreateCallback("{{request.Query.paymentid}}") }, UseTransformer = true } }) .RespondWith(Response.Create() .WithStatusCode(200) .WithHeader("Content-Type", "application/json")); ``` I don't know how to pass the custom header. And dosen't transform the fields in url
adam added the feature label 2025-12-29 15:24:11 +01:00
adam closed this issue 2025-12-29 15:24:12 +01:00
Author
Owner

@StefH commented on GitHub (Sep 30, 2022):

@ouell

That "x-origem" should work, did you test that it doesn't work?

And indeed, only the body and the headers can be transformed for now, however I can add logic to also transform the url.

@StefH commented on GitHub (Sep 30, 2022): @ouell That `"x-origem"` should work, did you test that it doesn't work? And indeed, only the body and the headers can be transformed for now, however I can add logic to also transform the url.
Author
Owner

@StefH commented on GitHub (Oct 1, 2022):

Preview version 1.5.6-ci-16508 supports transforming the url.

See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

https://github.com/WireMock-Net/WireMock.Net/pull/824

@StefH commented on GitHub (Oct 1, 2022): Preview version `1.5.6-ci-16508` supports transforming the url. See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions https://github.com/WireMock-Net/WireMock.Net/pull/824
Author
Owner

@StefH commented on GitHub (Oct 3, 2022):

@ouell
Did you have time to test this?

@StefH commented on GitHub (Oct 3, 2022): @ouell Did you have time to test this?
Author
Owner

@StefH commented on GitHub (Oct 12, 2022):

Can you please test?

Preview version = 1.5.7-ci-16520

@StefH commented on GitHub (Oct 12, 2022): Can you please test? Preview version = 1.5.7-ci-16520
Author
Owner

@StefH commented on GitHub (Oct 15, 2022):

PR is merged to master.
A new official NuGet will be released this weekend.

@StefH commented on GitHub (Oct 15, 2022): PR is merged to master. A new official NuGet will be released this weekend.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#456