vscode-restclient
vscode-restclient copied to clipboard
Multi-line variables
This might be a very niché request but it also might not be. I am in a situation where I need to talk to an API that accepts JSON inside of a form-encoded field
POST https://{{apiHost}}/path HTTP/1.1
Host: {{apiHost}}
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
&value=test
&attributes={ "some attribute here": "some value here" }
It's not the prettiest of API's but it's what we have to work with, the list of attributes can get quite large and I'd like to assign this to a variable with formatted json but put it inside of the form-encoded field like so:
@attributes = {
"some attribute here": "some value here",
"another attribute": 4
}
POST https://{{apiHost}}/path HTTP/1.1
Host: {{apiHost}}
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
&value=test
&attributes={{attributes}}
I'm not sure what would be the best approach I was either thinking about wrapping it in curly braces or using a similar approach to Powershell where you'd use a backtick to allow a new line for single-line statements.
@Marvin-Brouwer this is not supported yet, but nice suggestion
I think to support multi line variables, the parser needs to know a start and end-tag that would not be part of the content. Like the three single/double quotes in python.
I've just found myself in a similar need. How about using ``` just like markdown to flag beginning and end of variable content:
@jsonvar = ```
{
"id": 123,
"some": "val"
}
```
In the vim client the syntax is like this:
:header = <<
Content-Type: application/json
Authorization: key
Just for reference. It might be an idea to use this?
I would love this too.
My first thought was the triple ticks or <<
@cartFragment <<END
fragment cartFields on Cart {
id
createdAt
updatedAt
}
END
How about just allowing JS execution for a var?
@variableName = {{ $call: './getPayload.js' }}
That way you can just return an object from js
, you could even possibly support ts
, json
, or yaml
.
And as an added bonus that would allow you to call a secret store for variables.
Any news or plans about this, this is something that would prove to be very useful