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

Need help to port axios code in bruno #116

Closed
sanbhattdeep opened this issue Mar 3, 2023 · 2 comments
Closed

Need help to port axios code in bruno #116

sanbhattdeep opened this issue Mar 3, 2023 · 2 comments

Comments

@sanbhattdeep
Copy link

Hi ,

As per my understanding bruno uses axios underneath as the http client library
so need help on how to use the below axios code in bruno for streaming the response

const response = await axios.get(https://stream.example.com, {
headers: {Authorization: Bearer ${token}},
responseType: 'stream'
});

How to port this to bruno?
const stream = response.data
stream.on('data', data => {
data = data.toString()
console.log(data)
})

went through the docs here https://docs.usebruno.com/scripting/
So axios will be like an in-built library or an external library?

@helloanoop
Copy link
Contributor

Axios is not a built in library and must be installed externally.

You can create a package.json at the root of your collection and do npm i axios

Then inside scripting you can require axios like const axios = require('axios') inside your script. Infact, you can use any npm module of your like this.

console.log will not currently work, as it is executed in the node process. Will be building functionality to make logs visible in app.

With the streaming stuff, are you trying to write some test scripts that can be run and write tests to validate your streams response data ?

@helloanoop
Copy link
Contributor

Hi @sanbhattdeep

Bruno now supports both node-fetch and axios npm packages by default.
We also recently implemented support for making synchronous requests work as a part of #138

Here is a sample axios code to await a synchronous request.

const axios = require("axios");

const response = await axios.get("https://api.github.com/users/usebruno");

bru.setVar("avatarUrl", response.data.avatar_url);

Docs: https://docs.usebruno.com/scripting/sync-requests.html

Let us know if you run into further issues.

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

No branches or pull requests

2 participants