Using beforeRequest to modify the request object
See original GitHub issueI would like to use a JS file to modify the request json payload before it’s sent to the server. But it seems like it doesn’t actually effect the request object from what I’m seeing on the server.
My helper JS
const moment = require("moment");
exports.currentTime = (req, context, events, next) => {
const unixTime = moment()
.unix()
.valueOf();
req.json.timestamp = unixTime;
return next();
};
In my config:
...
config:
processor: "../utils/helpers.js"
...
- name: "Flow name"
weight: 2
flow:
- post:
beforeRequest: "currentTime"
url: "/api/route"
json:
timestamp: 123
When I look at the request on my server, I’m getting timestamp
to be 123
and not the current time.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to modify request body before reaching controller in ...
Use AOP to change the request before the method is called. Create an HTTP filter. Create a custom Spring HandlerInterceptor.
Read more >Modifying a Request or Response - Fiddler Classic
It is possible to use objects from the request inside OnBeforeResponse; however, ... Change a request for one page to a different page...
Read more >RequestHandler2 (AWS SDK for Java - 1.12.372)
A request handler is executed on a request object before it is sent to the client ... For this reason, we recommend that...
Read more >How to change request body before sending request - Help
I just want to modify the request body before request sent. I'm reading data from json and few fields will have array of...
Read more >StackedRequestHandler (AWS SDK for Java - Core 1.11.291 API)
beforeRequest (Request) method using AmazonWebServiceRequest.addHandlerContext(HandlerContextKey, Object) , and return your cloned message from this method. You ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ran into the same problem. My workaround was to remove
json:
from the config file and then settingreq.json = { timestamp: unixTime }
in the helper JS file instead. (using v.1.6.0-12)@misozask , try using:
status: "{{status}}"
(note the double quotations marks). See also this post for a complete example.I had a similar problem and it got resolved once I added the double quotations.