Reputation: 33
I should download json file on button click. When I click, I make a request to api and the following response:
{
data: {…},
status: 200,
statusText: "",
headers: {…},
config: {…},
…
}
but how can I download json file on button clicking with this response from backend?
Upvotes: 1
Views: 4376
Reputation: 3095
You can use a library like downloadjs
import downloadjs in the the component where your button is. attach a onClick event listenerr to your button and perform the following operation using downloadjs
download(JSON.stringify(apiResponse), "apidata.json", "text/plain");
Upvotes: 2