Last active
August 29, 2015 14:08
-
-
Save electricimp/b2a0d4cf83fa9d72ff7a to your computer and use it in GitHub Desktop.
Agent Incoming HTTP Request Handling Recipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define an HTTP request handler | |
function requestHandler(request, response) | |
{ | |
try | |
{ | |
if ("setting" in request.query) | |
{ | |
// 'setting' is a URL-encoded parameter, ie. '/setting=4' | |
local settingValue = request.query.setting | |
// Use the 'response' object to acknowledge reception of the request | |
// to the request's source. '200' is HTTP status code for 'OK' | |
respsonse.send(200, "Setting received and applied") | |
} | |
} | |
catch (error) | |
{ | |
// Something went wrong; inform the source of the request | |
// '500' is HTTP status code for 'Internal Server Error' | |
response.send(500, error) | |
} | |
} | |
// Register the handler function as a callback | |
http.onrequest(requestHandler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
response
is misspelled on line 16.