How to download file with Axios and format to xlsx

Diko_Mahendra
2 min readJul 12, 2022

Hi guys, thanks for coming, and I hope this can help for solved your issue.

so yesterday I getting task for download documents and format it to xlsx, and I want to share my experience, in this case I use real project with REST API, and Im using axios for handler request data to endpoint.

let say we have task “please create feature download documents and format to xlsx” and I giving you endpoint for download documents,

endpoint: http://baseurldummy.com/api/v1/documents/all

method: ‘GET

[Noted: the endpoint is only examples]

and for the response like this

image 1.1

let’s create the code.

the first is I will make a function for handler fetching data with axios

image 1.2

make sure your response is as expected like above (image 1.1)

after that, let create a simple button to trigger event onClick from button,

image 1.3

and your documents is ready to download and save it your local computer.

Thank you :)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Diko_Mahendra
Diko_Mahendra

Written by Diko_Mahendra

Frontend Engineer at Telkom Indonesia

Responses (1)

Write a response