Axios vs Fetch | KPITENG

KPITENG
2 min readJun 22, 2021

--

Axios vs Fetch HTTP Request

KPITENG

Hello Developers! All we are using either Axios OR fetch to communicate/exchange data with server. Both works perfect as per your requirement. Today we will go in detail and see how they are differ in terms of features they provide.

1. Request URL

Axios — has url in request object

Fetch — has no url in request object.

2. Package

Axios — third-party package that you need to install manually. 85.3k Star in Github — Well managed & rich features library.

npm i axios

Fetch — is in-build into most of the browser, no more need of installation.

3. CSRF Protection

Axios — having in-build support of CSRF (Cross site request forgery) to prevent cross-site request.

Fetch — doesn’t support CSRF

4. Request Data

Axios — request data contain object, you can directly sent JSON Object in request data

Fetch — request data should stringify

If you want to start New React Project — Check out React Clean Architecture

5. Response Parsing

Axios — in-built transform response to JSON for developers

fetch — has two step process, first response convert to json and then in second process developer will get json response

6. Cancel Request

Axios — In case user left the screen/component, axios allow developers to Cancel request

Fetch — doesn’t support Cancel API request

7. Request Interceptor

Axios — having in-build feature of intercept HTTP Request

Fetch — Doesn’t provide a way to intercept http requests.

8. Upload/Download Request Progress

Axios — Support developers to provide data transmission progress so developers can show loading indicator while user communicating with server

Fetch — Doesn’t support Upload/Download progress

9. Browser Support

Axios — have side browser capability support

Fetch — only support limited browsers & version , like Chrome 42+, Firefox 39+, Edge 14+, Safari 10.1.

Thanks for reading full article!

Read More Technical Articles

KPITENG || hello@kpiteng.com ||DIGITAL TRANSFORMATION

Connect Us — Linkedin | Facebook | Instagram

--

--

KPITENG
KPITENG

No responses yet