Joshua Osko
05/23/2024, 7:42 PM/api/v1/endpoint?from=1715887464&to=1716492264
where to
is always now but from
is some time before now .
Currently using the wiremock/wiremock:2.35.1-1 docker imageAntonio Pérez Dieppa
05/24/2024, 8:36 AMLee Turner
05/24/2024, 8:37 AM{{request.query.from}}
{{<http://request.query.to|request.query.to>}}
You can also parse a date in a unix format:
// Format can also be unix (epoch seconds) or epoch (epoch milliseconds)
{{date (parseDate request.headers.MyDate format='unix')}}
Obviously a lot of this will depend on what you want to do in your response but hopefully that will get you started.
Also, it is worth noting that the format of how query parameters are accessed from the request changed so you might need to take a look at that for the version you are running. You are on a crazy old version of WireMock. Is there a reason you can't use the latest (3.6.0)Antonio Pérez Dieppa
05/24/2024, 8:37 AMJoshua Osko
05/31/2024, 1:37 PMto_timestamp
query param and a from_timestamp
query param. The rest of the request is the same, but two of the params are unix timestamps and they will change each time this endpoint is called. Essentially we want to have three different responses: one for returning data over either the last day, last week, or last hour; however the service we are mocking here uses timestamps so we can't just statically use some tag like "last-week" and hence there will always be different values for these timestamps each time this endpoint is called. We are not trying to format the datetime or change the query params in any way. In other words if we make the request 100 times there would be 100 different `to_timestamp`s and 100 different `from_timestamp`s, but the delta between the to_timestamp and from_timestamp would either be an hour, a day, or a week. We want to map those 100 different to_timstamps and 100 different from_timestamp combos to one of 3 potential responses (this is a demo data system and we are presenting data over these three different time ranges)
I'm unclear on how the response templates would work for this. I want to change the entire response based on the difference between the two query params
Will upgrade our wiremock - had no idea it was that out of date. hahLee Turner
06/01/2024, 12:56 PMdaysBetween
, weeksBetween
and the more generic timeBetween
which might have helped here. The implementation of handlebars we are using doesn't have those helpers which is a shame. I don't think it would be too hard to put a WireMock extension together that adds these helpers if that was something you fancied looking at?