Rest API
$.rest ( options )
- options.url - end point URL to be hit
- options.headers (optional) - http headers to to passed
$.rest({
url : 'https://api.first.org/data/v1/countries',
header : {
'X-Amz-Target' : 'XAmzTargetValue'
}
});
get ( query )
It will execute prepared request with GET method- query - query params
$.rest({
url : 'https://api.first.org/data/v1/countries',
}).get({
region : 'Africa'
});
post ( json )
It will execute prepared request with POST method with application/json request body- json - json body
$.rest({
url : 'https://api.first.org/data/v1/countries',
}).post({
region : 'Africa'
});
submit ( fields )
It will execute prepared request with POST method with application/x-www-form-urlencoded- fields - map with fields values
$.rest({
url : 'https://api.first.org/data/v1/countries',
}).submit({
region : 'Africa'
});
json ( handler )
Parse response as json and hand it over to handler- handler - handler method
function onMessageReceive(){
$.rest({
url : 'https://api.first.org/data/v1/countries',
}).submit({
region : 'Africa'
}).json(myHandler);
}
function myHandler(json) {
return $.reply({
text : {
body : json.toString()
}
})
}