AnWeber / httpyac

Command Line Interface for *.http and *.rest files. Connect with http, gRPC, WebSocket and MQTT
https://httpyac.github.io/
MIT License
432 stars 38 forks source link

$random is not defined #803

Closed butonic closed 3 weeks ago

butonic commented 1 month ago

Hey! thanks for httpYac, awesome tool to replace postman with files I can use in CI as well as the IDE.

I can happily run this request in VSCode:

{{
  const filename = new Buffer($random.alphabetic(50)+'.test', 'utf-8').toString('base64');
}}
// @title initiate first upload
// @name upload1
POST {{baseUrl}}/remote.php/webdav
Tus-Resumable: 1.0.0
Upload-Length: 10
Upload-Metadata: filename {{filename}}, mtime 1712677748, filetype application/zip,
Content-Length: 0
Authorization: Basic {{username}}:{{password}}

?? status == 201 Created

{{
  uploadlocation1 = response.headers.location;
}}

###
// @title finish first upload
// @description This request should fail because another upload has created the same file.
// @name patch1
// @ref upload1
PATCH {{uploadlocation1}}
Tus-Resumable: 1.0.0
Content-Length: 10
Upload-Offset: 0
Content-Type: application/offset+octet-stream

1234567890

?? status == 204 No Content

Love it!

now to make this work with Intellij I understand that it uses different fencing:


< {%
  const filename = new Buffer($random.alphabetic(50)+'.test', 'utf-8').toString('base64');
%}
// @title initiate first upload
// @name upload1
POST {{baseUrl}}/remote.php/webdav
Tus-Resumable: 1.0.0
Upload-Length: 10
Upload-Metadata: filename {{filename}}, mtime 1712677748, filetype application/zip,
Content-Length: 0
Authorization: Basic {{username}}:{{password}}

?? status == 201 Created

> {%
  uploadlocation1 = response.headers.location;
%}

###
// @title finish first upload
// @description This request should fail because another upload has created the same file.
// @name patch1
// @ref upload1
PATCH {{uploadlocation1}}
Tus-Resumable: 1.0.0
Content-Length: 10
Upload-Offset: 0
Content-Type: application/offset+octet-stream

1234567890

?? status == 204 No Content

.. and maybe use request.variables.set

However, I already get a $random is not defined error. Reading the docs I assumed this would work, wouldn't it?

AnWeber commented 1 month ago

now to make this work with Intellij I understand that it uses different fencing:

~~If it were that simple. Intellij only supports a minimized Scripting API. I am now trying to recreate this API as identically as possible. For example, the $random function is not allowed in the scripting area of Intellij (dynamic variables are not supported in scripting), so I don't pass the object into the context. It would be possible, but then httpyac would not be compatible with Intellij again. It is best to read the Intellij documentation to see what is supported. httpyac is more of a superset for this, or tries to be.~~

Since when are dynamic variables are supported in scripting: https://www.jetbrains.com/help/idea/exploring-http-syntax.html#dynamic-variables. This is news for me. I will add support for $random with the next release

AnWeber commented 3 weeks ago

$random was added with commit https://github.com/AnWeber/httpyac/commit/96d311dad8d2395785455064fec9e6d56f930802 . I will release this version the next days