httpclient-fe-ml
v1.0.0
Published
normal http pooling connection manager.
Downloads
5
Readme
httpclient-fe-ml
Normal http pooling connection manager.
Installation
npm i httpclient-fe-ml
or install global
npm i -g httpclient-fe-ml
API
var Fetch = require('httpclient-fe-ml')
Fetch.postJson(url,data,success,error)
Send http request with post
method and convert result to json
format.
Call success
with request success and error
with request error.
// Fetch k1230.mlamp.co
Fetch.postJson('http://k1230.mlamp.co',{},function(data){},function(data){})
Fetch.postForm({url,data,dataType,success,error})
Send http request with post
method and convert result to given dataType format.
Call success
with request success and error
with request error.
// Fetch k1230.mlamp.co
Fetch.postForm({
url: 'http://k1230.mlamp.co',
data: {},
dataType: 'json',
success: function(data){},
error: function(data){})
Examples
Updating the Vary header when content is based on it
var Fetch = require('httpclient-fe-ml')
Fetch.postForm({
url: url,
data: params,
dataType: 'json',
success: (data) => {
var end = new Date().getTime(),_data = null;
console.log("["+url+"]执行时间:"+(end-start)+"ms");
if(data&&data.statusCode == 200)
_data = data.object;
if(typeof cb == 'function')
cb.call(null,_data);
},
error: (e) => {
var end = new Date().getTime();
console.log("["+url+"]执行时间:"+(end-start)+"ms");
if(typeof cb == 'function')
cb.call(null,null,e);
}
});
Testing
$ npm test