-
Notifications
You must be signed in to change notification settings - Fork 1
Request
Florian Bureau edited this page Jan 29, 2017
·
1 revision
This method allow you to call AppsPanel API.
- action : string, required, this is the URI endpoint you want to call (for example "test" if you want to call https://yourapp.apnl.ws/test)
- options : object, optionnal, an object with different options :
- method : default : "GET", to force the method
- deviceuid : default : "nodejssdk", set deviceuid (header : X-AP-DeviceUID)
- lang : default : "fr-FR", set lang (header : Accept-Language)
- format : default : "application/json", set format (header : Accept)
- appversion : default : "1.0", set appversion (header : X-AP-AppVersion)
- post_data : object with data to post (if set, method is changed to POST)
- success : a callback for request's success
- error: a callback for request's error
Simpliest call
var apnl = require('apnl')();
//very simple GET request on /test with get parameters foo, value FOO
apnl.request("test?foo=FOO");
GET with complete options and callback
var apnl = require('apnl')();
var options = {deviceuid: "mydevice", lang: "US-us", format: "application/json", appversion: "1.1"};
apnl.request("test?foo=FOO", options, function (data) {
//success
console.log("callback success");
console.log(data);
}, function (error) {
//error
console.log("callback error");
console.log(error);
});
POST
var apnl = require('apnl')();
//POST request on /test with get parameters foo (value FOO) with POST parameters provided in options document, and callback success and error provided
apnl.request("test?foo=FOO", {post_data: {bar: "BAR"}}, function (data) {
//success
console.log("callback success");
console.log(data);
}, function (error) {
//error
console.log("callback error");
console.log(error);
});