Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Prompt for input a variable #1033

Open
paulo-dc opened this issue Nov 23, 2023 · 11 comments
Open

[Feature Request] Prompt for input a variable #1033

paulo-dc opened this issue Nov 23, 2023 · 11 comments
Labels
enhancement New feature or request

Comments

@paulo-dc
Copy link

Is it possible to add to possibility to have a "prompt variable" ?

It's just for convienience to be able to set a variable à the request execution. For example, we could have such request :

GET : {{base_url}}/myapi/v1/mystuff/users/{{$prompt userId}}/details

And so, instead of copy/paste an id directly in the url form before the request run, we would be able to simply execute the request without modifying it, and a pop up would appear letting us set the id to replace the {{$prompt userId}} field.

Such feature exists at the moment in Insomnia. It would be very cool to have this in bruno.

@MelGrubb
Copy link

I have a handful of investigative and "repair" queries that I sometimes need to run with the Id of a specific user, for example. Which user I run the query or mutation for will never be the same twice, but I don't want to end up hard-coding the Id directly in the query. For the moment, I just have to remember to replace the Id with something bogus before saving the query for next time, but it would be a far better experience if I were prompted for the values each time I run the query. Ideally, the pop-up would remember the last value used, at least for the current session, so that I don't have to keep pasting it in each time. If I were to close the tab, the value should be forgotten, though, so I don't accidentally use the same value the next time I have to do a similar investigation.

I'd be fine if there were simply a way to mark a property on the Variables tab as being transient, perhaps the "{{$" syntax suggested above. I could specify my value directly on the Variables tab, just as long as I know that when I save the query, that value will get dropped from the file or something. Whatever is easiest. I just don't want that Id to make it into the file permanently, that's all.

@LuccaRomanelli
Copy link

This is really usefull so I could change values in query and body and it does not get carry on to other user and to my git

@simongodard
Copy link

Likewise, I have a lot of API requests to investigate and the IDs are always different. If the env variable is not set, there could be an option to prompt for the value.

@koljatm-edeka
Copy link

koljatm-edeka commented Feb 5, 2024

I would suggest adding a script method for that like
bru.prompt('varName', default, prompt)
so you can initialize a var in a pre script.
If that is something that's seen as useful I could imagine trying my hand on such a functionality

KoljaTM pushed a commit to KoljaTM/bruno that referenced this issue Feb 9, 2024
- bru.prompt(varName, prompt) allows to specify variables that should be prompted in a pre- or post-request script
@KoljaTM
Copy link

KoljaTM commented Feb 9, 2024

image Added a possible implementation of this feature. Open to suggestions.

@sanjai0py sanjai0py added the enhancement New feature or request label Apr 8, 2024
@LoganEarl
Copy link

+1 to this idea
This works well for requests that simulate an OAuth flow. I want to be able to enter an authorization code per request so that it doesn't get saved and doesn't change anything in VCS.

The PR hasn't had any updates for a few months, is this still on the radar?

@Streamlinesx
Copy link

I am also interested in this workflow, I think it would feel very natural for requests that have parameters that change a lot

@dvargas46
Copy link

dvargas46 commented Jul 23, 2024

I'm interested in a feature like this as well; it's usually a thing I look for coming from Insomnia.

But in the meantime I found out that the electron-prompt npm module can be used to make this kind of behavior, or at least for my use case. For anyone interested, you can follow these steps:

  • navigate to your collection's folder and run
    npm install electron-prompt --save
  • edit your bru.json file to include whitelist section for the dependent electron module
    {
      ...,
      "scripts": {
        "moduleWhitelist": ["electron"]
      }
    }
  • start using it in a pre-request script
    const prompt = require('electron-prompt')
    // many other options here: https://github.com/p-sam/electron-prompt?tab=readme-ov-file#options-object-optional
    const input = await prompt({
      title: 'Enter a value',
      label: 'Value',
      value: 'Default Value',
      type: 'input',
      inputAttrs: {type: 'text', required: true}
    })
    // set request body directly
    req.body.value = input
    // or set a variable for later
    bru.setVar('value', input)
  • then you can optionally create a wrapper function in the bru object
    // in collection-level Pre Request script
    bru.prompt = async (title, label, value) => {
      const prompt = require('electron-prompt')
      return await prompt({
        title,
        label,
        value,
        type: 'input',
        inputAttrs: {type: 'text', required: true}
      })
    }
    
    // ---
    // in request-level Pre Request script
    const input = await bru.prompt('Enter a value', 'Value', 'Default Value')
    // ...

From my initial testing, this only works in the Script tab and not the Vars tab expressions. Outcome looks like this
image

I know it's not exactly the OP request, but it worked for what I was looking for, so figured I'd share it here until we have a proper builtin solution.

@BerndO67
Copy link

I'm interested in a feature like this as well; it's usually a thing I look for coming from Insomnia.

But in the meantime I found out that the electron-prompt npm module can be used to make this kind of behavior, or at least for my use case. For anyone interested, you can follow these steps:

I followed exactly the steps provided to use prompts via Electron, but Bruno just shows the following error:

Error invoking remote method 'send-http-request': VMError: Cannot find module 'electron'

@BerndO67
Copy link

I'm interested in a feature like this as well; it's usually a thing I look for coming from Insomnia.
But in the meantime I found out that the electron-prompt npm module can be used to make this kind of behavior, or at least for my use case. For anyone interested, you can follow these steps:

I followed exactly the steps provided to use prompts via Electron, but Bruno just shows the following error:

Error invoking remote method 'send-http-request': VMError: Cannot find module 'electron'

Fixed it - typo in bruno.json

@Sigafoos
Copy link

Sigafoos commented Nov 5, 2024

+1 for this. I'd prefer to not have to add dependencies and script each variable in each request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests