Skip to content

simple web service example

Dave Conway-Jones edited this page Sep 11, 2013 · 1 revision

#Simple Web Service

Returns a simple web page in response to an http web request

How-to

  • deploy and then browse to http://localhost:1880/who?name=Joe

     [{"id":"db7299ac.0c56d8","type":"debug","name":"","complete":false,"x":708.0000190734863,"y":1761,"wires":[]},{"id":"a950c4fc.c82de","type":"http in","name":"","url":"/who","method":"get","x":155.0000343322754,"y":1733.9999589920044,"wires":[["3cff023d.cb968e"]]},{"id":"3cff023d.cb968e","type":"template","name":"Simple page","template":"<html><body><h1>Hello {{req.query.name}} !</h1>\nYou are using a browser of type <b>\n{{req.headers.user-agent}}\n</b><br/>Your IP address is <b>\n{{req.ip}}\n</b>\n</body></html>","x":343.99996185302734,"y":1767,"wires":[["c96b0990.6c07d8"]]},{"id":"c96b0990.6c07d8","type":"function","name":"Respond to http","func":"\n// this line send the actual page back\nmsg.res.send(200, msg.payload);\n\n// this carries on as normal, they don't have to be the same\nreturn msg;","outputs":1,"x":530.0001754760742,"y":1730.9999589920044,"wires":[["db7299ac.0c56d8"]]},{"id":"2040c311.20cee4","type":"comment","name":"browse to http://{your-ip}:1880/who?name=Fred","x":269,"y":1691,"wires":[]}]
    

Clone this wiki locally