From 5923c88a94ac190d3edd028c55071229a6bbde70 Mon Sep 17 00:00:00 2001 From: Daniel Luna Date: Wed, 6 Nov 2019 23:19:27 -0300 Subject: [PATCH 1/2] Added download button --- pages/index.vue | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pages/index.vue b/pages/index.vue index 1593eba62..b81bf019f 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -262,6 +262,7 @@ > file_copy + +
@@ -677,6 +682,7 @@ export default { preRequestScript: "", copyButton: 'file_copy', copiedButton: 'done', + downloadedButton: 'cloud_done', isHidden: true, response: { status: "", @@ -1535,6 +1541,37 @@ export default { 1000 ); }, + + downloadResponse(){ + // Storing the data in a organized way + var dataToWrite = JSON.stringify(this.response.body, null, 2); + // Default filename, maybe its better to add the url requested ? + var filename = 'response' + // Creating the Blob with data and mimetype + var file = new Blob([dataToWrite], {type: 'application/json'}); + // Create a "a" element + var a = document.createElement("a"), + url = URL.createObjectURL(file); + + // Point "a" element to url of new to be downloaded + a.href = url; + // Makes "a" element downloadable with filename + a.download = filename; + // Appends the brand new "a" element on body. + document.body.appendChild(a); + // Finally click on element to download it! + a.click(); + this.$refs.downloadResponse.innerHTML = + this.downloadedButton + "Downloaded"; + this.$toast.success("Download started, check your browser", { + icon: "done" + }); + setTimeout(function() { + document.body.removeChild(a); + window.URL.revokeObjectURL(url); + }, 0); + + }, togglePreview() { this.previewEnabled = !this.previewEnabled; if (this.previewEnabled) { From 7d070810d5e9e22b12852c70360711dba634bc4c Mon Sep 17 00:00:00 2001 From: Daniel Luna Date: Wed, 6 Nov 2019 23:21:38 -0300 Subject: [PATCH 2/2] Updated README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5cf0ccc85..aec34abf6 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ _Customized themes are also synced with local session storage_ 👋 **Responses**: Contains the status line, headers and the message/response body. - Copy response to clipboard + - Download response to a local file - View preview for HTML responses _HTML responses have "Preview HTML" feature_