react实现异步插件_react闲谈——推荐几个github上超级star的异步插件

如果你还在为选择哪个异步插件烦恼,不如静下心来看看下面这几个插件,或许会给你带来一些灵感。

原作者自认为这个插件是设计的最最最简单的异步操作,例如这个例子,并且默认支持https,如果看到这种写法觉得很好用,赶紧点击链接去看看吧。

var request = require('request');

request('http://www.google.com', function (error, response, body) {

if (!error && response.statusCode == 200) {

console.log(body)

}

})

基于promise写法的http请求插件,支持客户端和node端,有很好的一些特性:

支持restful API

支持拦截请求和响应

自动转换JSON数据

客户端支持保护安全免受XSRF攻击

...

axios.get('/user?ID=12345')

.then(function (response) {

console.log(response);

})

.catch(function (response) {

console.log(response);

});

兼容性有点渣渣,慎用。

request

.post('/api/pet')

.send({ name: 'Manny', species: 'cat' })

.set('X-API-Key', 'foobar')

.set('Accept', 'application/json')

.end(function(err, res){

// Calling the end function will send the request

});

还有几个几百、几千star的就不推荐了。

你可能感兴趣的:(react实现异步插件)