Huachao / vscode-restclient

REST Client Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=humao.rest-client
MIT License
5.21k stars 433 forks source link

Variables in body file #442

Open cortopy opened 4 years ago

cortopy commented 4 years ago

I'm aware than https://github.com/Huachao/vscode-restclient/issues/427 has already been closed, so I'm making a request to change the design so that we can use variables in request bodies imported from files.

When doing SOAP requests, they may have a very big XML body. In an .http file, vscode does not recognise the xml and I can't use features like commenting a line or a block. When trying out different options in the request this is important.

In my SOAP requests the authentication happens in the <SOAP-ENV:Header> so I do need the variables to work if I want to import a .xml file

pzelnip commented 4 years ago

To add to this, not being able to use variables in request bodies is a dealbreaker. We have saved requests where the request body contents differ by environment (for example: GET a document by ID, and that ID will be different depending on environment), so without the ability to define those values in environments, there's no way to use VSCode REST Client for those requests (whereas in say Postman, it's perfectly valid to use variables in request bodies).

Huachao commented 4 years ago

@pzelnip my extension supports variables in request body, you can try it. What the issue tracks is that my extension doesn't support variables in imported body file

pzelnip commented 4 years ago

Ahh, my mistake, I was doing it wrong. I had tried:

{
  "id": {{$id_from_settings}}
}

And was seeing id_from_settings in the body. Shouldn't have that $ in front, and then works. Thanks for the clarification.

timkinnane commented 4 years ago

Hello and thanks for the great work, really appreciate this extension.

I have a very similar request. I need to include stringified JSON as a request variable from a file. I am using the extension to test a common GraphQL request, with a range of large string inputs. I'd like to keep the content in files so I can easily switch between them.

This could use the same syntax as importing request bodies, but as a variable. e.g.

POST gql/url

mutation {
  MyQuery (input: {
    userId: "id",
    eventType: "event",
    content: "{{< ../content/success.txt}}"
  })
}

Or possibly by assigning a file variable with the import first if that's more clear?

@content = < ../content/success.txt

###

POST gql/url

mutation {
  MyQuery (input: {
    userId: "id",
    eventType: "event",
    content: "{{content}}"
  })
}
aligjonatas commented 11 months ago

Guys, theres is some news about that? I'm trying to get part of request from a external file and doesn't work.

My case:

@pdf_base64 = < ./my_file.json

### ----------------------------

# @name Post_File
POST {{url}}/api/v1/Document/Post HTTP/1.1
Content-Type: application/json
Authorization: Bearer {{accessToken}}

{
    "Sender": "me@test.com.br",
    "Subject": "My Test",
    "Files": [
        {
            "FileName": "pdf_teste.pdf",
            "Base64File": "{{pdf_base64}}",
            "FieldA": "123",
            "FieldB": "ABC"
        }
    ]
}

The C# api is receiving '< ./my_file.json' in property value, instead of a content file.