Vscode-restclient: A way for empty string as value of variable

Created on 2 Feb 2019  路  9Comments  路  Source: Huachao/vscode-restclient

empty string '' is widely used in url parameters, is there any way to declare a variable to be empty string?

maybe something like

@q={{$empty}}

I am using a workaround now, config

    "rest-client.environmentVariables": {
        "$shared": {
            "empty": ""
        }
    },

then {{empty}} could be used inside .rest file.

but it is not elegant enough, so a system variable may be necessary

feature request

Most helpful comment

@lihuanshuai @borekb @pranayrauthu I have published this in the latest release 0.23.1 and you can verify it with the following syntax.

http @empty =
The trailing whitespaces are allowed, that means you can add some whitespaces after the equal sign, and the spaces will be removed in the evaluated result

All 9 comments

@lihuanshuai Can you provide me with more details about the usage of empty string?

@Huachao sorry for late reply. I am testing an api with different parameter groups. The code looks like:

@param1 = test1
@param2 = test2

# @param1 = default
# @param2 = {{empty}}

GET https://{{host}}/api/items
        ?param1={{param1}}
        &param2={{param2}}

In this way, I could comment/uncomment some lines to switch parameters. yet, some parameter may be '' as a default value, if there is no {{empty}}, there won't be a way to declare such variable.

You may say, comment/uncomment &param2={{param2}} line is an option, yet isn't it too complicated? (linter will complain too). So, I think a variable for empty string will be useful.

@lihuanshuai thanks for your reply, in my view, the two methods provided from you, that a query parameter like param2= and without param2 query parameter may be different for some server web frameworks. So if they act the same, they uri may look like GET https://api.example.com?param1=, right?

@Huachao right. even they act the same, I prefer using the {{empty}} way.

We have an API that looks like this:

/products?filter=some-filter

When some-filter is empty, all products (unfiltered) are returned.

The proposed feature would allow for a .http file like this:

@filter =
# or `@filter = {{EMPTY}}` or something

GET {{apiroot}}/products?filter={{filter}}

This is currently invalid (and setting @filter = '' is a different thing).

UPDATE: @filter = (no space at the end of line) is invalid while @filter = _ (the _ indicates an empty space at the end of the line) is syntactically valid, but still doesn't work.

@borekb I am in favor of the proposed syntax without trailing space like Shell variables. If you have interest, a PR is welcomed

@lihuanshuai @borekb @pranayrauthu I have implemented this feature, and you can define empty file variables as following:

@empty =

The trailing whitespaces are allowed, that means you can add some whitespaces after the equal sign, and the spaces will be removed in the evaluated result

Sounds great! Will test it out when a new version is out. Thank you.

@lihuanshuai @borekb @pranayrauthu I have published this in the latest release 0.23.1 and you can verify it with the following syntax.

http @empty =
The trailing whitespaces are allowed, that means you can add some whitespaces after the equal sign, and the spaces will be removed in the evaluated result

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abenedykt picture abenedykt  路  18Comments

codepunkt picture codepunkt  路  29Comments

agjs picture agjs  路  31Comments

johnbeynon picture johnbeynon  路  23Comments

ryan-ju picture ryan-ju  路  17Comments