Hi, Is there a way to manipulate the request body ...
# help
m
Hi, Is there a way to manipulate the request body while recording and store the manipulated request body in the stub?. using transformer as mentioned in the https://wiremock.org/docs/record-playback/
Copy code
POST /__admin/recordings/start
{
  "targetBaseUrl": "<http://examples.wiremockapi.cloud/>"
}
transformer: [ "modify-request-body" ]
o
Hi. I don't think it is supported at the moment but it could be a good use case for a new extension
m
ok. This is my requirement , what I did and what I'm trying to do. I'm running 100s of test case against an api which helps me in testing registration form having multiple which includes Firstname, lastname , account number etc in different permutations and values like capturing the error json by passing empty entry for Firstname in one case, then passing empty account number for other request and capturing the different json response. The good part with WM is it records each of this permutation and stores the stub which is very good. The point that complicates thing is, this request form is sending the request body as string and has an entry that is dynamically generated. So even though I use the same value for forms with same set of permutations (always same) this dynamic entry in request body(request body is string) is making the replay fail. Now what i did in temporary basis:- I used Responsetransformer to parse the request body and write several if else conditions to check what fields state like are they empty /valid to provide appropriate response. This is so hard to maintain the logic as registration has several pages forms and I have to run several permutation and combinations in my test case to capture the response.Once I complete my recording I get around 2000 stubs. This one single dynamic value in the body makes everything difficult, both record and play and also in maintaining the logic. What I'm trying to do now:- 1. As mentioned- looking for option to edit the request body before storing the stub. In this way I can implement regex to accept the request just by ignoring that specific dynamic string. Editing each stub with regex after recording is time consuming. 2. The other way I'm thinking is, write a global request transformer that someway gets the recorded request body and newly incoming request body then do some parsing to check if the new and recorded are same except the dynamic filed. In this case I do not know how to pass the recorded request body. Can second point achievable with current set-up?.
Hi Oleg,
If I implement "Hi, Is there a way to manipulate the request body while recording and store the manipulated request body in the stub?. using transformer as mentioned in the" - Will the community accept my code, please?.
o
Hi. I will be happy to help with getting it integrated
m
Thank you. I'm interested in coding it. Now I'm trying to understand the code. I will reach you when I get a plan. Just a note, I'm new to coding side of IT so I would take time not as fast as a regular developer would take.
👍 1
o
Nice! Do not hesitate to use #help-contributing if you feel stuck
m
Sure, Thank you.