Class: http

http

Methods

(static) handle(callback, secure)

Setup a web request handler, requests to /app are forwarded to the handler function
Parameters:
Name Type Description
callback function Request Handler Callback Function
secure Boolean Enable AES256 End to End Encryption
Example
function handleHttp(req){

   print('URL:',req.url);
   print('Payload:',req.payload);

   return "Hello from web servr";
 }

 http.handle(handleHttp,false);

(static) req(url, payload, Timeout, secure) → {Object}

Launch a new web request
Parameters:
Name Type Description
url String request url
payload String Payload String, If used the request will be a POST request
Timeout Number MS
secure Boolean Enable AES256 End to End Encryption
Returns:
response object containing the error code and http response
Type
Object
Example
let request = {
 msg: "hello from client",
 epoch: datetime().epoch
};

let res = http.req(url,JSON.stringify(request),1000,false); // (1000 = timeoutMS, fase = AES encryption disabled)

if(res.err === 0 && res.code === 200) // Valid response, process it!
{

let payload = JSON.parse(res.payload); // Parse text payload into a JSON object

}