AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
222 stars 20 forks source link

JSON key that has spaces un-referencable when using variable injection #246

Closed Spitfire1900 closed 6 months ago

Spitfire1900 commented 6 months ago

I have the following script, I have attempted to use both {{login.JWT Authentication.rawHeaderValue}} and {{login.'JWT Authentication'.rawHeaderValue}} to re-use the JWT Authentication key's rawHeaderValue property from the login response body; however I get the following errors:

ERROR: SyntaxError - Unexpected identifier 'Authentication'
c:\Users\XXXXX\Repos\jwt-issue.http:12
exports.$result = (login.JWT Authentication.rawHeaderValue);
ERROR: SyntaxError - Unexpected string
c:\Users\XXXXX\Repos\jwt-issue.http:12
exports.$result = (login.'JWT Authentication'.rawHeaderValue);

Script

@baseUrl = https://mycompany.com/echoRequest
# @name login
GET {{baseUrl}}
Authorization: Basic {{$dotenv USERNAME}}:{{$dotenv PASSWORD}}

###
# @ref login
GET {{baseUrl}}
Authorization: Bearer {{login.'JWT Authentication'.rawHeaderValue}}
Spitfire1900 commented 6 months ago

This is resolved using bracket notation, while part of the JavaScript spec docs on this at https://httpyac.github.io/guide/metaData.html#name would be useful.

 GET {{baseUrl}}
Authorization: Bearer {{login["JWT Authentication"].rawToken}}
AnWeber commented 6 months ago

Can you give me suggestions how to improve the docs ( see https://httpyac.github.io/guide/variables.html#nodejs-script). I already mentioned usage of NodeJS.

Spitfire1900 commented 6 months ago

This may be closed as a skill issue.