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

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

1、request:https://github.com/request/re...(10K+ star)

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

var request = require('request');
request('http://www.google.com',function (error,response,body) {
  if (!error && response.statusCode == 200) {
    console.log(body)
  }
})

2、Axios:https://github.com/mzabriskie...(10K+ star)

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

支持restful API
支持拦截请求和响应
自动转换JSON数据
客户端支持保护安全免受XSRF攻击
...

axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (response) {
    console.log(response);
  });

3、superagent:https://github.com/visionmedi...(9K+ star)

兼容性有点渣渣,慎用。

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 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...
react 本身提供了克隆组件的方法,但是平时开发中可能很少使...
mobx 是一个简单可扩展的状态管理库,中文官网链接。小编在接...
我们在平常的开发中不可避免的会有很多列表渲染逻辑,在 pc ...