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

¿Load file into a variable? #294

Closed sir-farfan closed 1 month ago

sir-farfan commented 1 month ago

Hello

I know I can read the contents of a file and use them as body with <@ ./requestBodyImport.json

But, is there a similar shortcut to read the file into an exported variable in order to use it multiple times for different tests?

{{
  export.cert = ( < ./cert.pem ).toString('base64')
  export.key = ( < ./key.pem ).toString('base64')
}}

###
POST /myapp
{
  "cert": "{{cert}}",
  "key": "{{key}}",
}
AnWeber commented 1 month ago

It is also possible to store the file in a variable using the import syntax. The file is then read in as a string.

@foo={{< ./requestBodyImport.json}}

If you want to read the file yourself using Javascript, the easiest way is to use the methods provided by NodeJS directly (see https://nodejs.org/api/fs.html#filehandlereadfileoptions)