Script request: HTTPServer
Closed this issue · 2 comments
lauramielke commented
I am struggling with how to use the HTTPServer and would love to see your take on it. Could you maybe add a script using the HTTPServer? So far it seems the only feature not represented in this extensive and helpful script collection.
Anyway, thanks for the awesome work so far, its a lot of fun to check it out!
eurich commented
Here's a mini example, hope that helps you understanding the HTTPServer endpoint.
HTTPServer.registerEndpoint('testserver', function (req, res) {
// check request and comapare the querystring
if (req.query === 'turn=on') {
// response with some text
res.body = 'Shelly Webserver: on';
res.code = 200;
res.send();
// Do something, e.g. Shelly.Call();
} else if (req.query === 'turn=off') {
// response with some text
res.body = 'Shelly Webserver: off';
res.code = 200;
res.send();
// Do something else, e.g. Shelly.Call();
}
else {
res.body = 'Shelly Webserver';
res.code = 200;
res.send();
}
})
can be called via
http://<ip>/script/<id>/testserver?turn=on
is the script ID
is the Shellies ip address.