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

[Feature Request] Support environment variables in defaultHeaders

Open loverde opened this issue 7 years ago • 9 comments

Please enhance the rest-client.defaultHeaders setting so that it supports environment variables (specifically in the value of the header, but might as well implement it in both the key and value).

Steps to Reproduce:

  1. Define a defaultHeader that uses an environment variable, e.g.
    "rest-client.environmentVariables": {
        "$shared": {
            "access_token": "123"
        }
    },
    "rest-client.defaultHeaders": {
        "Authorization": "Bearer {{access_token}}"
    }
  1. Submit a request.

The outgoing request contains the raw value

Authorization: Bearer {{access_token}}

But ideally it would contain:

Authorization: Bearer 123

loverde avatar Aug 17 '18 15:08 loverde

It might also be nice, albeit probably a separate feature request to allow the defaultHeaders to be specified based on the HTTP method. E.g. to specify application/json for POSTs. Something like:

rest-client.defaultHeaders {
    "$shared:" {
        "Authorization": "Bearer {{access_token}}"
    },
    "POST": {
        "Content-Type": "application/json"
    }
}

loverde avatar Aug 17 '18 15:08 loverde

@loverde nice suggestion, I will consider this feature request carefully.

Huachao avatar Aug 23 '18 05:08 Huachao

This feature would be super useful.

Also, thanks for this amazing VS Code extension @Huachao . I might never use Postman again...

tfnaylor avatar Aug 25 '18 15:08 tfnaylor

Is this issue being worked on at all? I'd love to see this so I can add a unique correlation id to each request to my API for tracing purposes, so I would use the global var {{$guid}}.

erodewald avatar Jun 14 '19 20:06 erodewald

I have this implemented in my fork (one line change) but I'm not sure it would get merged. I can share the code if anyone's interested.

jnorkus avatar Mar 27 '20 15:03 jnorkus

And one more vote for this.

konradperzyna avatar Sep 22 '23 14:09 konradperzyna

@Huachao thank you for the great extension! Is this topic still under discussion, or is there another way to use variables in the default headers I missed? (=

NickRimmer avatar Sep 25 '23 11:09 NickRimmer

And one more vote for this.

EffNox avatar Oct 04 '23 16:10 EffNox