mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Is there a way to access templated data after transformation? #571
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 @vovka15 on GitHub (Feb 8, 2024).
Hello!
Question:
Is there a way to access templated data after transformation?
Context:
I am trying to perform some operations on response body AFTER transformation happened and THEN respond with modified body.
Example:
Request:
I have possibility to access it's body by using templates. So code would look like this:
But the problem is I want to modify some fields of that request and add new field that depends on values that arrive in the given request - for example, operation that concatenates all received fields and returns base64 value of it.
So I want to pass received request in some function, manipulate it's data and only then return response.
I've tried that stupid solution, but it of course doesn't work.
Maybe there is solution, but I did not find any in the current wiki.
Can you please tell is there possibility to do that?
@StefH commented on GitHub (Feb 8, 2024):
@vovka15
A possible way would be to use the existing Handlebars functions, see the documentation from Handlebars.Net for details.
In case, there is no function available, maybe a function is present in https://github.com/Handlebars-Net/Handlebars.Net.Helpers (for example Dynamic
If that is also not enough, you can write the function in c# with:
WithBodyand a callback function --> https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/ResponseBuilders/IBodyResponseBuilder.cs#L29@vovka15 commented on GitHub (Feb 8, 2024):
Thanks for suggestions!
I will report later after tests
@vovka15 commented on GitHub (Feb 8, 2024):
I used second variant and it works like a charm.
Thanks a lot!