usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
25.81k stars 1.18k forks source link

Access to interpolated values for scripting purposes #2569

Open elazzabi opened 3 months ago

elazzabi commented 3 months ago

I have checked the following:

Describe the feature you want to add

Currently, during the scripting phase, it is not possible to get interpolated values.

For example: req.getUrl() will return {{baseURL}}/users/{{userId}} instead of localhost:3000/users/123.

I believe it's better to have these values interpolated by default. Or at least provide both options.

This https://github.com/usebruno/bruno/discussions/1469 is related

Mockups or Images of the feature

For two options:

  getUrl() {
    return this.req.url;
  }

  getInterpolatedUrl() {
    return interpolateString(this.req.url);
  }

Or by default:

  getUrl() {
    return interpolateString(this.req.url);
  }
elazzabi commented 3 months ago

I can raise a PR @helloanoop if you are okay with that! (And after confirming the direction)

Its-treason commented 3 months ago

I would rather have a bru.interpolate(target: string): string function, that can be generally used for all values inside the request.

Maybe even a req.interpolateAll() that interpolates all values inside the request. But this will be more complicated.

moreiarty commented 2 months ago

I'd personally also like this to resolve path params as well (i.e. variables prefixed with :)