How to download file with Axios and format to xlsx
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

let’s create the code.
the first is I will make a function for handler fetching data with axios

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,

and your documents is ready to download and save it your local computer.
Thank you :)