Link Search Menu Expand Document

JavaScript example - async/await

If your code supports async/await, we recommend using the axios package.

This example uses the axios package. Install with npm install axios.

const axios = require('axios'); 
const fs = require('fs');

// Replace YOUR_API_KEY and otherParameters etc with proper values

let apiURL = 'https://img.bruzu.com/?a.text=Test+from+code&apiKey=YOUR_API_KEY&otherParameters';

axios.get(apiURL, {responseType: "stream"} )  
.then(response => {  
    // Saving file to working directory  
    response.data.pipe(fs.createWriteStream("output.png"));  
})  
    .catch(error => {  
    console.log(error);  
}); 

Plain JavaScript (Node.js) example

If you prefer not to install an HTTP library for making the request. This example shows you how to use the API without any dependencies.

const http = require('https');
const fs = require('fs');

// Replace YOUR_API_KEY and otherParameters etc with proper values

const file = fs.createWriteStream("output.png");
const request = http.get("https://img.bruzu.com/?apiKey=YOUR_API_KEY&otherParameters",
    function(response) {
        response.pipe(file);
    })

Need help?

Let us know : support@bruzu.com. We always respond within 24 hours.