Capturing an HTTP Response

#1

I have a flow set up that begins with HTTP in node that receives requests from a .NET client. The parameters on the GET request are processed through a function node and then passed into an HTTP request node with authentication which calls into an external HTTP endpoint. The flows works fine and passes the response all the way back to the .NET client. My issue is that I would like to change this flow so that it is not simply a pass through. I would like to capture the response in the flow and then create my own response to pass back to the client. I am not sure how to intercept the response.

Thanks for any advice!

Here is an empty shell that represents the general architecture that I am speaking about:

[{"id":"2c221e71.ca7062","type":"http 
request","z":"c6b0bb8e.3be0c8","name":"","method":"GET","ret":"txt","url":"","x":160,"y":660,"wires": 
[["8d071770.4e79d8"]]}, 
{"id":"8d071770.4e79d8","type":"function","z":"c6b0bb8e.3be0c8","name":"","func":"\nreturn 
msg;","outputs":1,"noerr":0,"x":350,"y":660,"wires":[["3ccfd54e.c3e80a"]]}, 
{"id":"3ccfd54e.c3e80a","type":"http 
request","z":"c6b0bb8e.3be0c8","name":"","method":"GET","ret":"txt","url":"","x":550,"y":660,"wires": 
[["9bec86b7.399c68"]]},{"id":"9bec86b7.399c68","type":"http 
response","z":"c6b0bb8e.3be0c8","name":"","statusCode":"","headers":{},"x":740,"y":660,"wires":[]}]
0 Likes

#2

You flows isn't importable
but I'm assuming you have something like
[HTTP-IN]-[function]-[httprequest]-[http-out]

Can't you do what you want with
[HTTP-IN]-[function]-[httprequest]-[function where you do whatever modifications]-[http-out]

0 Likes

#3

Sorry about the import problem! The structure you have outlined is what I have. Will that work, putting the logic in between the request and the out? I'll try it. Using a visual programming tool, it is a bit confusing, because it looks like everything is flowing in one direction. I want to capture and alter the response - not the msg on the request to the final node.

0 Likes

#4

What response are you trying to alter?
I assumed you wanted to alter the data you get back from your http-request node before it is send back to your browser. So that your browser receives a modified response.

0 Likes

#5

I want to retrieve the Response from the external (final) endpoint, extract a single property from the response and pass that back as the response to my client. So instead of the client getting the full response, it will only receive one property. I tried using a function where you suggested, setting msg.payload.Response to something else just to test. Unfortunately, the client (in this case I am testing with Postman, but could be a browser of course) is still receiving the full unaltered response.

0 Likes

#6

@ukmoose

Actually - I didn't have my function in the correct location. I switched to have the function directly between the request and response, it's working now! Thank you!

0 Likes