I am learning JavaScript and I can see, in multiple big projects, SuperAgent is being used for HTTP Request. I am using Axios for learning purpose, but wondering what makes SuperAgent different to Axios?
-
See also: https://stackoverflow.com/questions/40029787/axios-vs-superagent – Brad Aug 13 '18 at 03:48
-
Thank you @brad, but it's only answered in specific context, doesn't seem to cover all aspects. – Ishan Patel Aug 13 '18 at 03:52
-
There's an answer there that talks about a promise API vs. callback. Your question is very general... did you have any specific questions? – Brad Aug 13 '18 at 04:06
-
Thank you. @Brad I am just looking to get brief overview of both libraries so I could know which one I should use going forward. – Ishan Patel Aug 13 '18 at 04:28
-
Experiment with both, use whatever works best for your use. Both are using the same underlying Node.js libraries. – Brad Aug 13 '18 at 04:30
2 Answers
axios has more stars than superagent, check here
If you are doing front end, axios is probably more popular, e.g. vue uses axios, I am doing back end, either one works.
But just like one answer in 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 does not provide retry, https://github.com/axios/axios/issues/164. I really don't like the idea of introducing another module just for retry, not to mention there are already 2 different modules now, axios-retry
vs retry-axios
.
Besides, thru my limited test, this issue https://github.com/axios/axios/issues/553 has not been fully fixed.

- 10,295
- 11
- 80
- 129
-
2At the time I am writing this neither axios-retry or retry-axios work with axios 0.19.0 (released 4 months ago) 1. https://github.com/softonic/axios-retry/issues/94 2. https://github.com/JustinBeckwith/retry-axios/issues/62 – Anti Veeranna Oct 03 '19 at 11:36
-
As in 2023 there is another library called [alova](https://alova.js.org/), which specifically **aims** to compete with axios, and alova also provides [retry](https://alova.js.org/strategy/sensorless-data-interaction/request-retry/) – Qiulang May 17 '23 at 09:35
superagent
and axios
are HTTP client libraries. They are both very mature and picking between the two ultimately comes down to preference. Here's what it looks like to make a POST
request with a JSON body using each library:
// 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
}
})

- 1,429
- 1
- 16
- 37