Sample requests with super agent
const request = require('superagent')
Get
getWhatever(fnc){
return request.get(`${cfg.rest_api_endpoint}/whatever`)
.end(function(err, res){
if(err) fnc(err)
else{ fnc(null, JSON.parse(res.text)) }
});
}
Post
postWahtever(id, name, sizeX, sizeY, sizeZ, maxLoad, fnc ) {
return request.post(`${cfg.rest_api_endpoint}/whatever`)
.set('Content-Type', 'application/json')
.send({"id": id, "name": name, "sizeX": sizeX })
.end(function (error, response) {
if(error){ fnc(error) }
else{ fnc(null, response) }
})
}