HTTP Client
The Haplo HTTP client allows plugins to access external services via HTTP or HTTPS, such as APIs for third-party systems.
Interface
function O.httpClient(url)
This function creates a new HTTPClient object. The HTTP request is not performed at this point; further configuration may be performed before request() is called.
Example
P.myHTTPCallback = P.callback("myHTTPCallback", function(data, client, result) {
if(result.successful) {
// do something with result.body
} else {
P.data[data.target] = "Failure: " + result.errorMessage;
}
});
...
let client = O.httpClient("http://www.example.com/api").
method("PUT").
body("application/json", "{ver: '1.0', operation: 'help'}");
client.request(P.myHTTPCallback, {target: 'help-response'});
...
Note: be aware of the limitations of the plugin’s DataStore, consider using a Database to avoid race conditions when reading and writing in background tasks.