react闲谈——推荐几个github上超级star的异步插件
发布时间:2020-12-15 07:37:03 所属栏目:百科 来源:网络整理
导读:如果你还在为选择哪个异步插件烦恼,不如静下心来看看下面这几个插件,或许会给你带来一些灵感。 1、request:https://github.com/request/re...(10K+ star) 原作者自认为这个插件是设计的最最最简单的异步操作,例如这个例子,并且默认支持https,如果看
如果你还在为选择哪个异步插件烦恼,不如静下心来看看下面这几个插件,或许会给你带来一些灵感。 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 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的就不推荐了。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |