Open mirkogolze opened 10 months ago
Would bru.setNextRequest(<requestName>
) help you? It does not allow you to run a request from inside a request, but it allows you to customize the request chaining. You can make the response (or response-properties) available in the next request via bru.setVar(<varName>, <value>)
and bru.getVar(<varName>)
.
Note: Jumping back to earlier requests / the same request currently confuses the UI, but under the hood (and in the CLI) it runs fine.
I want to use it in a pre-request-script. It think bru.setNextRequest(...)
will not perform the chosen request to run before the current request. Could work as a workaround, but would lead to bad workaround request constellations.
const result = await bru.runRequest('[folder]/[requestFile].bru');
There have been multiple asks for this feature. Would love to get a PR for this.
@helloanoop : I'm not sure about the "good first issue" tag -- the feature needs to be implemented in the CLI and in the UI. The UI tends to glitch when a request is being run multiple times.
@mj-h Would you be able to share a video of the glitch ?
@helloanoop : Here is a video of a colllection that uses bru.setNextRequest()
to jump back from the third to the first request.
Two issues:
https://github.com/usebruno/bruno/assets/20513065/26a37aaa-89ae-4267-acd4-63cc7f8d4a34
Hello,
@helloanoop : Here is a video of a colllection that uses
bru.setNextRequest()
to jump back from the third to the first request.Two issues:
Would this glitch be resolved?
Hello,
I'm very interested in this feature. I'd like to execute an "auth_request" within the current collection to populate "token" variables.
Is it possible to create a method within the Collection - Settings - Pre-request Script to achieve that?
const result = await bru.runRequest('auth.bru');
Like this
you can use any http client library to do the work like axios, take a look here:
const axios = require('axios')
const baseUrl = bru.getEnvVar("baseUrl")
const axiosInstance = axios.create({
baseURL: baseUrl + "auth/",
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
const data = {
"phone": bru.getEnvVar("authPhone"),
"phonePrefix": "+34",
"language": "es"
}
axiosInstance.post('requestPhoneValidation', data)
.catch(error => {
console.error('Authentication failed:', error);
});
const loginData = {
"token": bru.getEnvVar("smsCode"),
"id": bru.getEnvVar("authPhone"),
"data": "+34",
"type": "phone",
}
const response = await axiosInstance.post('login', loginData).catch(error => {
console.error('Authentication failed when login:', error);
});
const accessToken = response.data.tokens.token;
console.log(accessToken)
await bru.setVar("token", accessToken)
console.log("Token variable set")
I think it was mentioned in the discussions around Bruno. But I create here a feature request (If duplicate please close).
It would be useful to have the ability to start a request via script. E.g. to run a dependent pre-request.
The method in the bru-object should return the result of the assertions and the tests and give access to the response object as accessible in the post response script.