-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
How to send a request to a specific URL after sending response #589
Comments
You are looking for a hook / callback which will be triggered after the response has been returned? |
Yes. Hook/Callback would be generic. So, that we can do something like this https://blog.jdriven.com/2020/10/using-wiremock-in-an-async-environment/ But in addition, if we can have some predefined post-serve hook like sending request to URL and surface it via JSON configuration, so that one can configure it via JSON mapping files then it would be great. Although I am not sure is it possible to inject stub code here in json config file or not because most people will need some mechanism to get actual token and send in Auth header. Something like below: {
"Request": {
"Url": "/api/v1/checkin",
"Methods": ["post"],
"Body": {
"Matcher": {
"Name": "JsonMatcher",
"Pattern": {
"messageId": "mockMessageId409"
},
"IgnoreCase": true
}
}
},
"Response": {
"StatusCode": 409,
"Body": "{\"errors\":[{\"code\":\"wrong_checkin\",\"message\":\"messageId : {{JsonPath.SelectToken request.body \"$.messageId\"}} conflicted\"}]}",
"UseTransformer": true,
"Headers": {
"Content-Type": "application/json"
}
},
"PostServe": {
"Request": {
"Url": "http://auditmyoperation.com",
"Method" : "Post",
"Headers": {
"Authorization": " skslsljd ",
"Content-Type": "application / json"
},
"Body": {
"messageId": "{{JsonPath.SelectToken request.body \"$.messageId\"}}"
},
"UseTransformer": true,
}
}
} |
Dear @samiransaha, I did update your question with some code formatting so that it it's better readable. I think this can be implemented, however it will take some effort. And maybe instead of letting the user define the content, it's maybe easier to just forward the complete request and response to that callback hook. So that all data is present. "Hook": {
"Request": {
"Url": "http://auditmyoperation.com",
"Method" : "Post",
"Headers": {
"Authorization": " skslsljd ",
"Content-Type": "application / json"
}
} |
Thanks @StefH. |
@samiransaha Only Body or BodyAsJson is supported. No transformation (yet) example {
"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://any-url",
"Method": "POST",
"Headers": {
"x": "x-value"
},
"Body": "ok?"
}
}
} |
@samiransaha A new version Add |
Thanks @StefH, I will check it. |
I am using the wiremock as dotnet tool. How to get your CI version for that? |
See https://github.com/WireMock-Net/WireMock.Net/wiki/Faults |
it's on the same MyGet feed: PM> Install-Package dotnet-WireMock -Version 1.4.7-ci-14780 -Source https://www.myget.org/F/wiremock-net/api/v3/index.json |
Can we add Faults like no response at all? Correct me if I am wrong with the exiting Faults I will not be able to add delay before response or completely no response, to simulate server is down. Both are good candidate for fault for integration tests. |
@samiransaha Did you have time to test it ? |
@samiransaha Did you have to test? |
@samiransaha Can you please test this? |
@StefH , Hey sorry for delay, I got sick, and was not able to catch up my emails. I will test this today, and let you know. |
Hi @StefH, I used following rule it didn't work for me looks like.
{
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/api/user/mock_user_hook",
"IgnoreCase": false
}
]
},
"Methods": [
"get"
]
},
"Response": {
"StatusCode": 200,
"Headers": {
"Content-Type": "application/json",
},
"Body": "{
\"Id\" : \"mock_user_cess\",
\"Name\": \"Mock User\",
\"City\": \"London\"
}",
"UseTransformer": true
},
"Webhook": {
"Request": {
"Url": "http://localhost:8989/api/saas/subscriptions/order_delete_failure_403",
"Method": "delete",
"Headers": {
"mock-header": "hook-mock"
}
}
}
} |
Very strange, according to WIKI it looks fine. (https://github.com/WireMock-Net/WireMock.Net/wiki/Webhook) See also this unit tests (https://github.com/WireMock-Net/WireMock.Net/blob/819629125ce3f34e71a31ba6a8825a13b0b8adb1/test/WireMock.Net.Tests/WireMockServer.WebhookTests.cs) Did you try another address? |
Hey it worked now, there was network issue with that port for that time being. |
@samiransaha Thanks for testing. |
The java version of wiremock supports Post-serve actions mentioned here http://wiremock.org/docs/extending-wiremock/.
By using this we can send request to a specific URL after serving mocked response to a request. Is it possible to with wiremock.net? if yes, can we configure it via JSON and does it support authentication?
The text was updated successfully, but these errors were encountered: