我正在学习JavaScript,我可以看到,在许多大型项目中,HTTP请求都使用了SuperAgent。我使用Axios是为了学习,但是我想知道SuperAgent和Axios有什么不同?
发布于 2018-12-02 15:24:59
axios的明星比superagent多,check here
如果你在做前端,axios可能更受欢迎,例如vue使用axios,我在做后端,两者都可以。
但就像Axios vs Superagent中的一个回答所说的那样:“我会根据其他因素来决定,比如你更喜欢哪种API,以及库的大小。”我尝试了两种方法,最终选择了 superagent b/c superagent has build-in retry。
axios不提供重试,https://github.com/axios/axios/issues/164。我真的不喜欢仅仅为了重试而引入另一个模块的想法,更不用说现在已经有了两个不同的模块,axios-retry和retry-axios。
此外,通过我有限的测试,这个问题https://github.com/axios/axios/issues/553还没有完全解决。
发布于 2018-12-02 15:43:34
superagent和axios是超文本传输协议客户端库。他们都非常成熟,在两者之间做出选择最终取决于他们的喜好。下面是使用每个库发出带有JSON body的POST请求的样子:
// superagent
await request
.post('/to/my/api') // URI
.set('Authorization', authorizationKey) // Header
.send({ foo: 'bar' }) // Body
// then creates a promise that returns the response
.then(res => res.body) /* axios */
// axios exclusively returns promises
// URI, body, request options are provided in one call
await request.post('/to/my/api', {
foo: 'bar'
}, {
headers: {
Authorization: authorizationKey
}
}) https://stackoverflow.com/questions/51814935
复制相似问题