Skip to content

Any advice on using fetch vs. axios vs. mithril's xhr? #2963

Answered by panoply
EverettMcKay asked this question in Q&A
Discussion options

You must be logged in to vote

It depends. For 95% of usage cases, XHR suffices and (imo) is a better choice. I base this on the following (incoming opinions):

JSON Parsing
This is huge for me. In XHR, there is no need to process JSON because we have response type as json, whereas in fetch you need to manually parse the response (await response.json()). This always bothered me and continues to bother me.

Progress Events
This is native in XHR, whereas in fetch (IIRC) you need to use a readable stream.

Native Timeout
XHR has timeout control available natively for request cancellation, while in fetch you'll need to use Abort Controller.

Error Handling
XHR differentiates between different types of errors, which makes thing…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@dead-claudia
Comment options

Answer selected by EverettMcKay
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants