RESTful API using node-red-contrib-db2-for-i
Simple REST API from a Db2 table.
Simple scenario, RESTful services , CRUD , no security or access management.
You'll find the database DDL used in this example (CUSTCHURN) in the 'IBM i and AI' github repo
[{"id":"59087ca1.9463cc","type":"http in","z":"ff512e80.f6dac","name":"","url":"/customers","method":"get","upload":false,"swaggerDoc":"","x":100,"y":240,"wires":[["f4c0394b.9bb75"]]},{"id":"f4c0394b.9bb75","type":"function","z":"ff512e80.f6dac","name":"SQL Query","func":"msg.payload=\"select * from churn.custchurn3\";\n//where customerid='9237-HQITU'\" \n//\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":240,"wires":[["d8119035.e53dc8","8b12ac80.ca17f","d44c7e0d.311cc","30b4ac06.f95f44"]]},{"id":"30b4ac06.f95f44","type":"DB2 for i","z":"ff512e80.f6dac","mydb":"5b23748.69bd60c","name":"","arraymode":true,"x":506.5,"y":325,"wires":[["f28bf350.d5f9c","ced76e43.26752"]]},{"id":"a3ab5971.ea7bf8","type":"inject","z":"ff512e80.f6dac","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":120,"wires":[["f4c0394b.9bb75"]]},{"id":"f28bf350.d5f9c","type":"change","z":"ff512e80.f6dac","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":683,"y":327,"wires":[["e1a0f47.8528308"]]},{"id":"ced76e43.26752","type":"debug","z":"ff512e80.f6dac","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":666.5,"y":513,"wires":[]},{"id":"7cdf85ac.c8280c","type":"function","z":"ff512e80.f6dac","name":"SQL Query","func":"msg.payload=\"select * from churn.custchurn3 where customerid='\"+ \nmsg.req.params.id+\"'\"\n//\"9237-HQITU\";\nreturn msg;","outputs":1,"noerr":0,"x":309,"y":409,"wires":[["30b4ac06.f95f44"]]},{"id":"8a61e9cf.8c477","type":"function","z":"ff512e80.f6dac","name":"SQL Query","func":"msg.payload=\"update churn.custchurn3\" +\n\" set \"+\n\"GENDER='\"+msg.req.body.GENDER +\"',\"+\n\"SENIORCITIZEN\t='0' \"+\n\"where customerid='\"+ \nmsg.req.params.id+\"';\";\n\n//curl -X PUT -H 'Content-Type: application/json' -i 'http://10.7.19.71:1880/customers/0019-EFAEP' --data '{\"CUSTOMERID\":\"0019-EFAEP\",\"GENDER\":\"Female\",\"SENIORCITIZEN\":\"0\",\"PARTNER\":\"No \",\"DEPENDENTS\":\"No \",\"TENURE\":\"72\",\"PHONESERVICE\":\"Yes\",\"MULTIPLELINES\":\"Yes \",\"INTERNETSERVICE\":\"Fiber optic\",\"ONLINESECURITY\":\"Yes \",\"ONLINEBACKUP\":\"Yes \",\"DEVICEPROTECTION\":\"Yes \",\"TECHSUPPORT\":\"No \",\"STREAMINGTV\":\"Yes \",\"STREAMINGMOVIES\":\"No \",\"CONTRACT\":\"Two year \",\"PAPERLESSBILLING\":\"Yes\",\"PAYMENTMETHOD\":\"Bank transfer (automatic)\",\"MONTHLYCHARGES\":\"101.30\",\"TOTALCHARGES\":\"7261.25\",\"CHURN\":\"No \"}'\n//\"GENDER=\t'Female'\n//\"SENIORCITIZEN '0'\n//PARTNER\t\"No \"\n//DEPENDENTS\t\"No \"\n//TENURE\t\"72\"\n//PHONESERVICE\t\"Yes\"\n//MULTIPLELINES\t\"Yes \"\n//INTERNETSERVICE\t\"Fiber optic\"\n//ONLINESECURITY\t\"Yes \"\n//ONLINEBACKUP\t\"Yes \"\n//DEVICEPROTECTION\t\"Yes \"\n//TECHSUPPORT\t\"No \"\n//STREAMINGTV\t\"Yes \"\n//STREAMINGMOVIES\t\"No \"\n//CONTRACT\t\"Two year \"\n//PAPERLESSBILLING\t\"Yes\"\n//PAYMENTMETHOD\t\"Bank transfer (automatic)\"\n//MONTHLYCHARGES\t\"101.30\"\n//TOTALCHARGES\t\"7261.25\"\n//CHURN\t\"No \"\n\nreturn msg;","outputs":1,"noerr":0,"x":315,"y":512,"wires":[["30b4ac06.f95f44","ced76e43.26752"]]},{"id":"e1a0f47.8528308","type":"http response","z":"ff512e80.f6dac","name":"","statusCode":"","headers":{},"x":845,"y":330,"wires":[]},{"id":"864b1b2d.78e61","type":"http in","z":"ff512e80.f6dac","name":"","url":"/customers/:id","method":"get","upload":false,"swaggerDoc":"","x":105,"y":410,"wires":[["7cdf85ac.c8280c"]]},{"id":"9162762f.cc424","type":"inject","z":"ff512e80.f6dac","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":300,"wires":[["7cdf85ac.c8280c"]]},{"id":"2a5e4e82.31dc62","type":"http in","z":"ff512e80.f6dac","name":"","url":"/customers/:id","method":"put","upload":false,"swaggerDoc":"","x":106,"y":514,"wires":[["8a61e9cf.8c477"]]},{"id":"5b23748.69bd60c","type":"DB2 for i Config","z":"","cnnname":"*LOCAL","db":"*LOCAL","keepalive":true}]