vscode-restclient icon indicating copy to clipboard operation
vscode-restclient copied to clipboard

Save Response Bytes as File

Open Joe-Zer0 opened this issue 5 years ago • 6 comments

First, I love this plugin and thank you for all your hard work. Second, I apologize if this was in the documentation and I missed it.

Is it possible to download a file with this plugin? Below is python code that I am using, but I would like to do this via the Rest Client if possible. Thank You!

response = requests.get(request_url,
    headers = {
        'Authorization': f'Bearer {access_token}'
    }
)

with open(FILE_NAME, 'wb') as file:
    file.write(response.content)

Joe-Zer0 avatar Nov 09 '20 15:11 Joe-Zer0

@Joe-Zer0 you need to preview the response first and click the Save Response and Save Response Body as you wish

image

Huachao avatar Nov 10 '20 02:11 Huachao

@Huachao thank you for the quick response. Save Response Body does what I want. Is there some notation I can use in the .rest file to redirect the output to a file?

Also I had one more question. I am attempting to send file data as well. The examples I found use multipart/form-data. I have tried to implement this, but I just get a 500 back from the server so I am doing something incorrectly. I'm only trying to send a single file do I want to use multipart/form-data? Below is working python code of what I'm trying to accomplish in the Rest Client.

response = requests.post(request_url,
    headers = {
        'Authorization': f'Bearer {access_token}'
    },
    files = {
        '': open(FILE_NAME, 'rb')
    }
)

Joe-Zer0 avatar Nov 10 '20 20:11 Joe-Zer0

Why not have something like this?

POST https://example.com/comments/export HTTP/1.1
Content-Type: application/xml
Authorization: token xxx

> ./comments-export.xml

Folloring the "convention" of request body?

POST https://example.com/comments HTTP/1.1
Content-Type: application/xml
Authorization: token xxx

< ./demo.xml
``

gustavorps avatar May 21 '21 15:05 gustavorps

I'm trying to save PDF's in a way that I can preview them using vscode-pdf plugin. This works only through ssh remote plugin when the PDF is in workspace folder. How can I set a custom default directory for storing bodies? I did not find a setting.

gerritgriebel avatar May 09 '23 14:05 gerritgriebel

This feature (automatic body saving) would be very useful to monitor API response stability and evolution.

  • test api, get response
  • > ./api-response.expected.json
  • add api-response.expected.json to git/SCM

Now when you run the api, any changes to api-response.expected.json get highlighted by git as changes

pasisavolainen avatar Feb 09 '24 09:02 pasisavolainen