When I run this request, it logs the changed url once, but then ends up running the original request.
If instead I call Util.foo() in the collection script or if I just put pm.request.url="foo" in the request pre- script, then it works as intended (fails, because it can’t find foo).
I wonder if there is some work around for this. I want to be able to define a function at the collection level, that will alter the url for some requests (folders actually), but it is rather tedious to have to write in in-line everywhere
This looks like a candidate to add to a script in the new Package Library - This types of workarounds are only there due to not having the capability to create those global, team based functions.
I kept the method as a GET on the main request so that you could see the request return a 404 due to the url change in the script. You’d also not need to add pm as an argument to the function.
This Package Library was only add in V11 so there will be certain scenarios that might need a bit of work but this simple case will work.