feross / simple-get

Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines
MIT License
401 stars 50 forks source link

Data method is always empty. When I do a simple request to a static JSON file and I log data, it will be undefined. #38

Closed jobsturm closed 6 years ago

jobsturm commented 6 years ago

Code:

class ApiController {
    constructor() {
        this.settings = apiSettings;
    }
    get() {
        console.log(this);
        request(apiSettings, (err, res, data) => {
            if (err) {
                throw err;
            }
            console.log('data', data);
            console.log('data', res);
        });
    }
}
bendrucker commented 6 years ago

Hi, take a closer look at the docs here. By default simple-get just calls back with err, res which allows you to streamingly process the response. If you want it to read the whole response stream into a buffer for you, you can use the provided concat method.