Passing a Parameter dynamically to response from request
Hi Team, We are trying to stub one Json response using hoverfly. Currently we are getting static response for any request. We are expecting to get one value dynamically(empID) in response that should be take from request.
Example: Request: {"employee":{"empName":"Naren","empDesg":Test,"empID":"76443",}}
Response: { "employee": { "empID":"76443" }, "status": "success" } So in the above example the empID value keep changing for all employees. So we want to get the empID dynamic value in response while stubbing through Hoverfly. Can you please help us here.
Can someone help me here?
You can use middleware to do that with Hoverfly in simulate mode. Both the request body and the corresponding response are available to the middleware. There is an example here and there's a SOAP example in the hoverpy documentation here. @tommysitu was showing me a Java example but I can't find that at the moment. Hopefully he can find it and post it.
I think the documentation could be clearer. Some of the diagrams do not show middleware being available in simulate mode.
@priyathamreddy6009 I need to point out that using request body for response templating is not supported yet, so the only way is using middleware as @JohnFDavenport suggested. You can have a look here to see what's available: https://hoverfly.readthedocs.io/en/latest/pages/keyconcepts/templating/templating.html
@priyathamreddy6009 You should be able to use response templating to do this in the next release, your response body should look like this:
"response": {
"status": 200,
"body": "{ \"employee\": { \"empID\": \"{{Request.Body \"jsonpath\" \"$.employee.empID\"}}\" }",
"templated": true
}
@tommysitu I liked the response templating feature you mentioned above. Do you have a link to its documentation?
@Teklie https://docs.hoverfly.io/en/latest/pages/keyconcepts/templating/templating.html
@Teklie https://docs.hoverfly.io/en/latest/pages/keyconcepts/templating/templating.html
Thanks @ns3777k !