mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Question : Extracting text from a request.body that is not json #142
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 @fransjvanderlinde on GitHub (Sep 6, 2018).
Hi is there any way to use the transformers to pull text from a requestbody by passing in a regex expression and using that value in response body. At moment it looks like code only caters for json to get info from a json node.
@StefH commented on GitHub (Sep 6, 2018):
Correct.
Currently it's only possible to use all functionality from Handlebars on a text string or on a json object.
Using RegEx (on a string), XPath (on a string) or Linq (on a json object) is not yet supported. I'm working on the last now.
@StefH commented on GitHub (Sep 7, 2018):
Hello @fransjvanderlinde, I could implement logic for
on the request body (string) using extensions on HandleBars, just like I did for https://github.com/WireMock-Net/WireMock.Net/wiki/Response-Templating#jsonpathselecttoken
So an example mapping for
Regex.Matchcould be:Would this idea be what you need?
@fransjvanderlinde commented on GitHub (Sep 7, 2018):
Yes that sounds like it will work. I did something like below in my app which did give me the values but i would like to do a lot more complex regex so solution suggested will work much better.
@StefH commented on GitHub (Sep 7, 2018):
Hi @fransjvanderlinde,
I've update the code to support this logic:
Regex.Matches
Regex.Match
Would this be as you would use it?
@StefH commented on GitHub (Sep 8, 2018):
Or maybe better to keep the name
Regex.Matchfor both?@fransjvanderlinde commented on GitHub (Sep 11, 2018):
Looks good. Thanks
@StefH commented on GitHub (Sep 11, 2018):
I'll create PR and new NuGet.