Axios 和 SuperAgent 库有什么区别?
What is the difference between Axios and SuperAgent libraries?
我正在学习JavaScript我可以看到,在多个大项目中,SuperAgent 正在用于 HTTP 请求。我将 Axios 用于学习目的,但想知道 SuperAgent 与 Axios 有何不同?
axios 比 superagent 拥有更多的星星,check here
如果你是做前端的,axios 可能更受欢迎,例如vue 使用 axios,我在做后端,两者都可以。
但就像Axios vs Superagent said "I’d base my decision on other factors, like which API you like better, and library size " I tried both and finally chose supergent b/c superagent has build-in retry
中的一个答案
axios 不提供重试,https://github.com/axios/axios/issues/164。我真的不喜欢为了重试而引入另一个模块的想法,更不用说现在已经有 2 个不同的模块,axios-retry
vs retry-axios
。
此外,通过我有限的测试,这个问题https://github.com/axios/axios/issues/553还没有完全解决。
superagent
和 axios
是 HTTP 客户端库。他们都非常成熟,在两者之间做出选择最终归结为偏好。这是使用每个库使用 JSON 正文发出 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
}
})
我正在学习JavaScript我可以看到,在多个大项目中,SuperAgent 正在用于 HTTP 请求。我将 Axios 用于学习目的,但想知道 SuperAgent 与 Axios 有何不同?
axios 比 superagent 拥有更多的星星,check here
如果你是做前端的,axios 可能更受欢迎,例如vue 使用 axios,我在做后端,两者都可以。
但就像Axios vs Superagent said "I’d base my decision on other factors, like which API you like better, and library size " I tried both and finally chose supergent b/c superagent has build-in retry
中的一个答案axios 不提供重试,https://github.com/axios/axios/issues/164。我真的不喜欢为了重试而引入另一个模块的想法,更不用说现在已经有 2 个不同的模块,axios-retry
vs retry-axios
。
此外,通过我有限的测试,这个问题https://github.com/axios/axios/issues/553还没有完全解决。
superagent
和 axios
是 HTTP 客户端库。他们都非常成熟,在两者之间做出选择最终归结为偏好。这是使用每个库使用 JSON 正文发出 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
}
})