Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ouell opened this issue Sep 30, 2022 · 5 comments
Closed

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

ouell opened this issue Sep 30, 2022 · 5 comments
Labels

Comments

@ouell
Copy link

ouell commented 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:https://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

@ouell ouell added the bug label Sep 30, 2022
@StefH
Copy link
Collaborator

StefH commented 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
Copy link
Collaborator

StefH commented 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

#824

@StefH
Copy link
Collaborator

StefH commented Oct 3, 2022

@ouell
Did you have time to test this?

@StefH
Copy link
Collaborator

StefH commented Oct 12, 2022

Can you please test?

Preview version = 1.5.7-ci-16520

@StefH
Copy link
Collaborator

StefH commented Oct 15, 2022

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

@StefH StefH closed this as completed Oct 15, 2022
@StefH StefH added feature and removed bug labels Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants