We received a question recently from one of our prospects.
"I wanted to know about the advanced usage of dynamic rules. How do I add scripting for my response logic? I need some date comparisons for calculating some fields values, is it possible to with scripting or handlebars?" - Software Developer working for a gaming company.
You can add scripting to your response login with scripts or handlebars. Here is the documentation on how to do that: https://trafficparrot.com/documentation/5.50.x/dynamic.html
Handbars should be enough for this simple case of comparing dates.
For example, you can add this into your response body like on the screenshot displayed below:
{{#if (gt (date (parseDate request.query.SomeDate format='dd-MM-yyyy')) (date (now)))}}Response if the defined date is after now
{{else}}
Response if the defined date is not after now
{{/if}}
This code compares SomeDate request query parameter with today's date and returns a different response based on that comparison.
Here is an example result:
support@support-pcs:/optf/git$ curl http://localhost:8081/hello?SomeDate=01-01-2024
Response if the defined date is not after now
support@support-pcs:/optf/git$ curl http://localhost:8081/hello?SomeDate=01-01-2025
Response if the defined date is after now
No comments:
Post a Comment