flow.json 3.3 KB

1
  1. [{"id":"1e002bcb.5d43cc","type":"tab","label":"SimpleWebServices","disabled":false,"info":""},{"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":"\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":[]}]