thunderclient / thunder-client-support

Thunder Client is a lightweight Rest API Client Extension for VS Code.
https://www.thunderclient.com
Other
3.64k stars 131 forks source link

Support for generating random strings and integers in request body #136

Closed joekaiser closed 3 years ago

joekaiser commented 3 years ago

Is your feature request related to a problem? Please describe. Assume testing the CRUD lifecycle of a rest API. You need to be able to create/update/fetch/delete an entity. It would be nice if Thunder Client could generate random strings and integers to use in the request body.

Describe the solution you'd like Let's take the Create example. The request requires a name:string to be passed over. Perhaps you can do something similar to how environment variables are used. {{__randstring}}, maybe?

Describe alternatives you've considered An Alternative could be having "setups" as part of the request. Similar to how Tests work you can manipulate environment variables, and set the value to something random there. This way you can just use the environment variable as normal, but the value would change with every request.

Implementation:

rangav commented 3 years ago

Hi @joekaiser will guid work for random string?

joekaiser commented 3 years ago

Absolutely

I would imagine integers could even work. The need is for random data. At the end of the test the record is delete, so it doesn't matter what it is.

rangav commented 3 years ago

That’s Good, if possible I will include this for next update

annymosse commented 3 years ago

Absolutely

I would imagine integers could even work. The need is for random data. At the end of the test the record is delete, so it doesn't matter what it is.

i think Faker.js or Chancejs can help too much for this process .

rangav commented 3 years ago

I saw faker.js the size is around 6MB , which is too big to use. I will check the other one.

Any ultra lightweight library?

annymosse commented 3 years ago

@rangav actually faker is around 9.6MB PUBLISH SIZE & INSTALL SIZE however it's very huge because of the international data names (ar,fr,en,it,....) for chancejs 1.80MB PUBLISH SIZE & INSTALL SIZE with limited data and limited api compared to chancejs, you can remove the additional European the idea here is to keep only the main typography such as [en,it,es,...]=> latina and [ar,pr]=>ar and Chinese , only the main different characters.

joekaiser commented 3 years ago

I'm not suggesting how to build your product, but I don't see real fake data as something useful. I would imagine a string RNG number or UUID would solve 90%+ of all use cases

rangav commented 3 years ago

Hi all, started working on this, initially supports following variables

UPDATE: format will {{#randomString}}, hash # prefix and variable name

let me know your feedback.

Planning to release new update by end of today.

rangav commented 3 years ago

Update: the underscore prefix is sometimes clearly not visible so changing the prefix to #

the new format will {{#randomString}}

rangav commented 3 years ago

This feature is now implemented in v1.3.0 https://github.com/rangav/thunder-client-support/releases/tag/1.3.0 Let me know if any questions.

Docs Link https://github.com/rangav/thunder-client-support#variables