mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
How can send Postbacks based on a path? #537
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mastrauckas on GitHub (Jul 25, 2023).
Originally assigned to: @StefH on GitHub.
Is there a way to receive a request, respond to the client with a status code and body, and a minute later send a post back to a URL with information from the original client request body? If possible, maybe even send multiple postbacks at different times.
I thought I could do like this
The last part is obviously made up, but I was wondering if there is a feature that I can accomplish this?
Thanks
@StefH commented on GitHub (Jul 25, 2023):
You can use
.WithCallback(...)(https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithCallbackTests.cs)It's not yet possible to delay the callback or send multiple callbacks at different times. --> Why would you need this?
@mastrauckas commented on GitHub (Jul 25, 2023):
@StefH ,
Thanks for your quick reply.
So I experimented with some of the code below.
WithCallbackafterWithBody, theWithBodymethod never gets called so the body never gets sent to the client. If I switchWithBodyandWithCallback, then theWithCallbacknever gets called. So I haven't found a way for both methods to get triggered.WithCallback, I'm not able to get the response information returned from the HTTP server listening onBodyDestination. To tell you the truth, I'm not even sure the URL inBodyDestinationever got called.I'm sure I just don't know the correct way to use the API.
I am trying to emulate receiving a request from a client and sending back an immediate status code and body for the request and later sending partial updates via postbacks to a URL based on the original request the client sent me.
I hope that makes sense.
@StefH commented on GitHub (Jul 25, 2023):
@mastrauckas
Sorry.
I provided the wrong answer.
You should use WithWebhook
-->
@mastrauckas commented on GitHub (Jul 25, 2023):
@StefH,
Ok, so I made some tweaks as shown below:
I now send the response to the client with
.WithBody(request => GetResponseBody(request)), but once again I'm not getting a postback from the information passed into.WithWebhook(GetWebhook()).Even if I did get a postback from the information passed into
.WithWebhook(GetWebhook()), I don't have the original request to use when crafting the postback request body. I also don't seem to be able to get the response information from that postback server.@StefH commented on GitHub (Jul 25, 2023):
You can use Handlebars templating to access the request.
See this : https://github.com/WireMock-Net/WireMock.Net/wiki/Webhook
https://github.com/WireMock-Net/WireMock.Net/wiki/Response-Templating
@mastrauckas commented on GitHub (Jul 25, 2023):
Thanks. I will give that a tryout a little later.
@StefH commented on GitHub (Jul 31, 2023):
@mastrauckas
Did you have time to test this?
@StefH commented on GitHub (Aug 21, 2023):
@mastrauckas
Did you have time to test this?
@StefH commented on GitHub (Sep 4, 2023):
@mastrauckas
Did you have time to test this?
@Excommunicated commented on GitHub (Sep 28, 2023):
So I'm not OP, But I did test using the Webhook Json mapping as documented with one additional tweak
I added in the Delay parameter for the webhook, and was expecting to get a result back, and then see the webhook publish 20 seconds later, but instead it takes 20 seconds to send the webhook request, then returns the response body to my request. so my actualt mocked request takes 21 seconds and I get the webhook call, before I get the response to my original request.
@Excommunicated commented on GitHub (Sep 28, 2023):
I apologise, I missed the
UseWebhooksFireAndForgetelement in the mapping that solves this issue.@StefH commented on GitHub (Sep 29, 2023):
@mastrauckas
Did you have time to test this?
@StefH commented on GitHub (Oct 14, 2023):
@mastrauckas / @Excommunicated
Is all clear? Can I close this issue?
@Excommunicated commented on GitHub (Oct 14, 2023):
I’m good. It all worked for me as expected.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Stef Heyenrath @.>
Sent: Saturday, October 14, 2023 9:27:34 AM
To: WireMock-Net/WireMock.Net @.>
Cc: Excommunicated @.>; Mention @.>
Subject: Re: [WireMock-Net/WireMock.Net] How can send Postbacks based on a path? (Issue #982)
@mastrauckashttps://github.com/mastrauckas / @Excommunicatedhttps://github.com/Excommunicated
Is all clear? Can I close this issue?
—
Reply to this email directly, view it on GitHubhttps://github.com/WireMock-Net/WireMock.Net/issues/982#issuecomment-1762896329, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA2VR2RGSN4RYDBY23BU75TX7KHMNAVCNFSM6AAAAAA2WKHIYKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRSHA4TMMZSHE.
You are receiving this because you were mentioned.Message ID: @.***>
@StefH commented on GitHub (Oct 20, 2023):
closing...