Displaying an HTTP Response on a Web Page
In the previous tutorial example, we geocoded an address to identify the latitude and longitude of the location, found the current weather for that location, then displayed the result on the debug tab.
In this tutorial, we perform a similar operation but alter the existing flow to display the response on a web page using the http and http request nodes.
Using the HTTP and HTTP Request Nodes
1. | Delete the inject and debug nodes. You are left with the Geocode telogis api node, First Result function node, and Weather http request node. |
2. | Add and connect the new nodes you need for the tutorial: |
|
3. | Edit the Geocode telogis api node: |
|
4. | Edit the http node: |
|
5. | Edit the First Result function node: |
|
6. | Edit the Weather http request node: |
|
7. | Edit the change node: |
|
8. | Edit the template node: |
|
9. | From the Flow Editor, click the Deploy button in the upper right corner of the screen. |
10. | View the results on a webpage: |
|
The flow created in this tutorial is described by the JSON below. To successfully execute this flow, you must edit the tde rest node Config to add your own TDE credentials before you deploy.
To import a flow into the Editor, copy the code provided, click the upper right ≡ Menu button, then select "Import" > "Clipboard". Paste the code in the Import nodes window, then click Import.
Code:
[
{
"id": "a817dceb.b68dc",
"type": "telogis-api",
"z": "dc0465a8.949678",
"name": "Geocode",
"config": "fe8073e7.97922",
"endpointQueryString": "endpoint=/geocode/{{country}}/{{address}}&method=get",
"parameters": [
{
"name": "country",
"value": "USA",
"in": "path"
},
{
"name": "address",
"value": "20 Enterprise, Aliso Viejo",
"in": "path"
}
],
"x": 340,
"y": 80,
"wires": [
[
"329d76db.6686ea"
]
]
},
{
"id": "329d76db.6686ea",
"type": "function",
"z": "dc0465a8.949678",
"name": "First Result",
"func": "var temp = msg.payload[0];\nmsg.geocode = temp;\nmsg.payload = temp;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 510,
"y": 80,
"wires": [
[
"1688e6fb.bda109"
]
]
},
{
"id": "1688e6fb.bda109",
"type": "http request",
"z": "dc0465a8.949678",
"name": "Weather",
"method": "GET",
"ret": "obj",
"url": "https://api.darksky.net/forecast/c86b0fbbac42edf4850112cc77c0c890/{{{payload.lat}}},{{{payload.lon}}}",
"x": 680,
"y": 80,
"wires": [
[
"140cf413.dfe6cc"
]
]
},
{
"id": "1e665dda.b64ae2",
"type": "http in",
"z": "dc0465a8.949678",
"name": "",
"url": "/WeatherNow",
"method": "get",
"x": 150,
"y": 80,
"wires": [
[
"a817dceb.b68dc"
]
]
},
{
"id": "140cf413.dfe6cc",
"type": "change",
"z": "dc0465a8.949678",
"name": "",
"rules": [
{
"t": "delete",
"p": "headers",
"pt": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 880,
"y": 80,
"wires": [
[
"2bd527e2.eec348"
]
]
},
{
"id": "2bd527e2.eec348",
"type": "template",
"z": "dc0465a8.949678",
"name": "Webpage",
"field": "payload",
"fieldType": "msg",
"format": "html",
"syntax": "mustache",
"template": "<div style=\"text-align: center;font-family: sans-serif;\">\n <h1>Weather Today</h1>\n <p><em>Location:</em> {{geocode.street}}, {{geocode.city}}</p>\n <p><em>Current:</em> {{payload.currently.temperature}}° F</p>\n <p><em>Description:</em> {{payload.currently.summary}}</p>\n</div>\n",
"x": 1070,
"y": 80,
"wires": [
[
"6f0785bc.7f318c"
]
]
},
{
"id": "6f0785bc.7f318c",
"type": "http response",
"z": "dc0465a8.949678",
"name": "",
"x": 1210,
"y": 80,
"wires": []
},
{
"id": "fe8073e7.97922",
"type": "api-config",
"z": "dc0465a8.949678",
"proxy": "",
"instance": "production",
"custominstance": "https://api.telogis.com/",
"labelValue": "production - acme123:main",
"useMessageCredentials": "false",
"credentialsCustomer": "acme123",
"credentialsUser": "main"
}
]