flow.json 6.0 KB

1
  1. [{"id":"1e002bcb.5d43cc","type":"tab","label":"SimpleWebServices","disabled":false,"info":"This Tab (\"flow\") contains some simple examples showing how to make simple web-services in node-red."},{"id":"6e0db7f9.b70d7","type":"http in","z":"1e002bcb.5d43cc","name":"","url":"/nothing","method":"get","upload":false,"swaggerDoc":"","x":150,"y":160,"wires":[["51473d3c.ce53b4","f05ffc0f.7a46f"]]},{"id":"382e6d8b.409542","type":"http response","z":"1e002bcb.5d43cc","name":"","statusCode":"","headers":{},"x":630,"y":160,"wires":[]},{"id":"51473d3c.ce53b4","type":"function","z":"1e002bcb.5d43cc","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":160,"wires":[["382e6d8b.409542"]]},{"id":"f05ffc0f.7a46f","type":"debug","z":"1e002bcb.5d43cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":290,"y":200,"wires":[]},{"id":"e8e45ef.0c3bca","type":"comment","z":"1e002bcb.5d43cc","name":"GETing /nothing","info":"The endpoint of this service will be [http://localhost:1880/nothing](http://localhost:1880/nothing) if you are running Node-RED locally with default settings.\n\nTry sending some name/value pairs using a query string in your browser.\n\nCheck out the output of the debug node. Note that the debug node is set to output the whole msg object, not just the `msg.payload`. The `req` and `res` objects are specific for http nodes. You have to pass through the `res` object to the http response node, so that the http response node knows that it is responding to the appropriate http request, logical. Your name/value pairs will be in the payload. Compare `msg.payload` with `req.query` and check out also `req.headers`.\n\nFor more Info check out:\n - Node-RED help of the **http in** and **http response** nodes\n - [https://www.w3schools.com/tags/ref_httpmethods.asp](https://www.w3schools.com/tags/ref_httpmethods.asp)\n - search the www for HTTP GET\n\n\n\n","x":160,"y":120,"wires":[]},{"id":"2ce5990d.653366","type":"http in","z":"1e002bcb.5d43cc","name":"","url":"/sum","method":"get","upload":false,"swaggerDoc":"","x":140,"y":380,"wires":[["5048ebc9.21c3f4","f0cd78fa.c9f62"]]},{"id":"96538fc8.f0985","type":"http response","z":"1e002bcb.5d43cc","name":"","statusCode":"","headers":{},"x":630,"y":380,"wires":[]},{"id":"f0cd78fa.c9f62","type":"function","z":"1e002bcb.5d43cc","name":"","func":"var key, sum = 0\nfor (key in msg.payload) {\n if (msg.payload.hasOwnProperty(key)) {\n sum = sum + Number(msg.payload[key])\n }\n}\nmsg.payload = \"The sum of your values is \" + sum + \".<br> I didn't care about they names in your name/value pairs!\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":380,"wires":[["96538fc8.f0985","72160b2f.cfebe4"]]},{"id":"5048ebc9.21c3f4","type":"debug","z":"1e002bcb.5d43cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":290,"y":420,"wires":[]},{"id":"e1e63a04.eab72","type":"comment","z":"1e002bcb.5d43cc","name":"GETing /sum","info":"Read the previous comment.\n\n\n\n","x":150,"y":340,"wires":[]},{"id":"72160b2f.cfebe4","type":"debug","z":"1e002bcb.5d43cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":420,"wires":[]},{"id":"6acd862e.9508c8","type":"comment","z":"1e002bcb.5d43cc","name":"Listening to a POST request","info":"You can't HTTP POST something using the address bar of a usual browser.\nYou can POST by using a html form action attribute, check out: [https://www.w3schools.com/tags/att_form_action.asp](https://www.w3schools.com/tags/att_form_action.asp)","x":200,"y":520,"wires":[]},{"id":"c33c5ae6.799ae","type":"http in","z":"1e002bcb.5d43cc","name":"","url":"/do-something","method":"post","upload":false,"swaggerDoc":"","x":170,"y":560,"wires":[["d441787d.4df498"]]},{"id":"d441787d.4df498","type":"function","z":"1e002bcb.5d43cc","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":560,"wires":[["ada1fe20.5db528"]]},{"id":"ada1fe20.5db528","type":"http response","z":"1e002bcb.5d43cc","name":"","statusCode":"","headers":{},"x":510,"y":560,"wires":[]},{"id":"129dcd30.c9ec13","type":"http request","z":"1e002bcb.5d43cc","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/do-something","tls":"","persist":false,"proxy":"","authType":"","x":1090,"y":640,"wires":[["739240e9.fdbc78"]]},{"id":"3ff30f3a.c17c28","type":"function","z":"1e002bcb.5d43cc","name":"","func":"msg.payload = \"This text was injected in Node-RED: \" + msg.payload + \"\\n ... and POSTed in the body of the request. \"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":960,"y":560,"wires":[["129dcd30.c9ec13","3924fdfc.235182"]]},{"id":"496e23ef.d7b86c","type":"inject","z":"1e002bcb.5d43cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"This msg.payload is injected to the next Node","payloadType":"str","x":790,"y":560,"wires":[["3ff30f3a.c17c28"]]},{"id":"739240e9.fdbc78","type":"debug","z":"1e002bcb.5d43cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1250,"y":640,"wires":[]},{"id":"9e991225.9225d","type":"comment","z":"1e002bcb.5d43cc","name":"POSTing something","info":"You can't HTTP POST something using the address bar of a usual browser.\nYou can POST by using a html form action attribute, check out: [https://www.w3schools.com/tags/att_form_action.asp](https://www.w3schools.com/tags/att_form_action.asp)","x":870,"y":520,"wires":[]},{"id":"3924fdfc.235182","type":"debug","z":"1e002bcb.5d43cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":640,"wires":[]}]