An easy way to call http server.
var $ = require('node-httpclient');
$.ajax({
url: 'http://www.yourdomain.com/api',
type: 'GET',
success: function(data, status){
console.log(data, status);
}
});
$.ajax('http://www.yourdomain.com/api', {
type: 'GET',
success: function(data, status){
console.log(data, status);
}
});
$.get('http://www.yourdomain.com/api', function(data, status){
console.log(data);
});
$.post('http://www.yourdomain.com/api', {name:'123'}, function(data, status){
console.log(data);
});
$.put('http://www.yourdomain.com/api',{name:'123'}, function(data, status){
console.log(data);
});
$.delete('http://www.yourdomain.com/api', function(data, status){
console.log(data);
});
var promise = $.get('http://www.yourdomain.com/api');
promise.then(function success(result){
console.log(result);
}, function error(result){
console.log(result);
});
var promise = $.get('http://www.yourdomain.com/api',{name:'123'});
promise.success(function success(result){
console.log(result);
}).error(function(result){
console.log(result);
});
promise.then(function success(result){
console.log(result);
}, function error(result){
console.log(result);
});
promise.success(function(result){
console.log(result);
}).error(function(result){
console.log(result);
});