Response TemplatingΒΆ

If you need to build a response dynamically based on the request data, you can do so using templating:


        // Using path in template
                "{'id':{{ Request.Path.[2] }},'origin':'London','destination':'Singapore','_links':{'self':{'href':'http://localhost/api/bookings/{{ Request.Path.[2] }}'}}}"

        // Using query Param in template
            .queryParam("destination", "London")
            .queryParam("page", any())
                "{'id':'1', 'destination':'{{ Request.QueryParam.destination }}','_links':{'self':{'href':'http://localhost/api/bookings?page={{ }}'}}}"

The first example sets the id in response body based on the last path segment in the request using {{ Request.Path.[2] }}. The second example sets some response body data based on the request param using {{ Request.QueryParam.destination }} and {{ }}.

For more details, please check out the Hoverfly documentation.