Set the URL of a request
Problem
You want to set the URL of an HTTP request node dynamically.
Solution
Set the URL property of the HTTP Request
node.
Example
Flow JSON
[{"id":"b36aa30.3a7276","type":"http request","z":"c9a81b70.8abed8","name":"","method":"GET","ret":"txt","url":"","x":470,"y":300,"wires":[["1ef9987c.956c78"]]},{"id":"11167f67.5d5031","type":"inject","z":"c9a81b70.8abed8","name":"cars on craigslist","topic":"","payload":"http://vancouver.craigslist.org/search/sss?format=rss&query=cars","payloadType":"str","repeat":"","crontab":"","once":false,"x":140,"y":300,"wires":[["70154cd4.de1444"]]},{"id":"70154cd4.de1444","type":"change","z":"c9a81b70.8abed8","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":300,"wires":[["b36aa30.3a7276"]]},{"id":"1ef9987c.956c78","type":"debug","z":"c9a81b70.8abed8","name":"","active":true,"console":"false","complete":"false","x":630,"y":300,"wires":[]}]
The Inject
node generates a string URL, and the Change
node sets the msg.URL property. In this flow the URL is set to:
http://vancouver.craigslist.org/search/sss?format=rss&query=cars
To return an RSS feed for cars for sale in Vancouver on Craigslist. It returns something like the following XML content in the debug window:
craigslist vancouver, BC | for sale search "cars"
https://vancouver.craigslist.ca/search/sss?query=cars
en-us
copyright 2017 craiglist
robot@craigslist.org
robot@craigslist.org
https://vancouver...
Discussion
An XML
node can be added after the HTTP Request
to change the XML RSS content returned to a JavaScript object for easy access to the data.