How to use the wreck.get function in wreck

To help you get started, we’ve selected a few wreck examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mtharrison / hapi.js-in-action / test / CH01.js View on Github external
setup('1.4', (err, child, stdout) => {

            if (err) {
                throw err;
            }

            Wreck.get('http://localhost:4000/', (err, res, payload) => {

                expect(err).to.not.exist();
                expect(payload.toString()).to.equal('Hello World!');

                Wreck.get('http://localhost:4000/json', (err, res, payload) => {

                    expect(err).to.not.exist();
                    expect(JSON.parse(payload)).to.deep.equal({ hello: 'World' });

                    // Check logging output

                    expect(getStreamBuffer(stdout)).to.include('[response]');
                    cleanup(child, done);
                });
            });
        });
github csabapalfi / pagespeed-score / lib / run-pagespeed.js View on Github external
async function runPagespeed(urlString, strategy) {
    const url = new URL(urlString);
    if(!url.hash) {
      // bust PSI cache but not your CDN's cache
      url.hash = `#${Date.now().toString().substring(6)}`
    }
    const queryOptions = {
      url: url.toString(),
      strategy: strategy || 'mobile',
    }
    const query = new URLSearchParams(queryOptions)
    const apiUrl = `${baseUrl}/?${query.toString()}`;
    const {payload} = await wreck.get(apiUrl, {json: true});
    return {result: payload.lighthouseResult};
}
github nelsonic / github-scraper / lib / stars.js View on Github external
module.exports = function stargazers (url, callback) {
  if(!url || url.length === 0 || typeof url === 'undefined'){
    return callback(400);
  }
  if(url.indexOf('page=') === -1) { // e.g: /tj/followers?page=2
    url = 'https://github.com' + '/' + url + '/stargazers'; // becomes https://github.com/{username}/followers
  }
  wreck.get(url, function (error, response, html) {
    if (error || response.statusCode !== 200) {
      callback(response.statusCode);
    }
    else {
      var data = { entries : [] }, u;
      var $    = cheerio.load(html);
      $('.follow-list-item').each(function () {
        u = $(this).find('a').attr('href').replace("/", "")
        data.entries.push(u);
      });
      var next = $('.pagination > a').filter(function () {
        return $(this).text() === "Next";
      });
      if(next.length > 0) {
        data.next = next['0'].attribs.href;
      }
github nelsonic / github-scraper / lib / following.js View on Github external
module.exports = function following (url, callback) {
  if(!url || url.length === 0 || typeof url === 'undefined'){
    return callback(400);
  }
  if(url.indexOf('page=') === -1) { // e.g: /tj/followers?page=2
    url = 'https://github.com' + '/' + url + '/following'; // becomes https://github.com/{username}/followers
  }
  wreck.get(url, function (error, response, html) {
    if (error || response.statusCode !== 200) {
      callback(response.statusCode);
    }
    else {
      var data = { entries : [] };
      var $    = cheerio.load(html);
      $('.follow-list-item').each(function () {
        data.entries.push($(this).find('a').attr('href').replace("/", ""));
      });
      var next = $('.pagination > a').filter(function () {
        return $(this).text() === "Next";
      });
      if(next.length > 0) {
        data.next = next['0'].attribs.href;
      }
      callback(error, data)
github hapijs / hapi / test / gzip.js View on Github external
it('returns a gzip response on a get request when accept-encoding: gzip is requested', function (done) {

        Wreck.get(uri, { headers: { 'accept-encoding': 'gzip' } }, function (err, res, body) {

            expect(err).to.not.exist;
            expect(body).to.equal(zdata);
            done();
        });
    });
github mtharrison / hapi.js-in-action / test / CH03.js View on Github external
setup('3.2.1', (err, child) => {

                if (err) {
                    throw err;
                }

                Wreck.get('http://localhost:4000/', (err, res, payload) => {

                    expect(err).to.not.exist();
                    expect(payload.toString()).to.include('DinDin Mobile Website');
                    cleanup(child, done);
                });
            });
        });
github mtharrison / hapi.js-in-action / test / CH05.js View on Github external
setup('5.1.3', (err, child, stdout, stderr) => {

                if (err) {
                    throw err;
                }

                Wreck.get('http://localhost:4000/', (err, res, payload) => {

                    expect(err).to.not.exist();

                    expect(res.statusCode).to.equal(403);
                    expect(getStreamBuffer(stdout)).to.include('Blocking request from 127.0.0.1. Within blocked subnet 127.0.0.0/8');
                    cleanup(child, done);
                });
            });
        });
github christophercliff / flatmarket / packages / flatmarket-service / lib / index.js View on Github external
return new Bluebird(function (resolve, reject) {
        Wreck.get(uri, options, function (err, res, payload) {
            if (err) return reject(Boom.serverTimeout(MISSING_SCHEMA_ERROR))
            return resolve([
                res,
                payload,
            ])
        })
    })
}
github ggoodman / plunker-run-plugin / facets / previews / methods / fetchProject.js View on Github external
return new Promise(function (resolve, reject) {
      Wreck.get(url, options, function (err, resp, payload) {
        if (err) return reject(err);
        
        resolve(payload);
      });
    });
  };
github mtharrison / hapi.js-in-action / CH8 - Leveraging Caching / 8.3 / 8.3.2 / index.js View on Github external
var searchReviews = function (query, callback) {

    var baseUrl = 'http://api.nytimes.com/svc/movies/v2/reviews/search.json';
    var queryObj = {
        'api-key': '2d07d4c26378607c5e104ae3164327ff:18:72077307',
        query: query
    };
    var queryUrl = baseUrl + '?' + Qs.stringify(queryObj);

    var options = { json: true };

    Wreck.get(queryUrl, options, function (err, res, payload) {

        callback(err, payload);
    });
};

wreck

HTTP Client Utilities

BSD-3-Clause
Latest version published 6 years ago

Package Health Score

56 / 100
Full package analysis

Popular wreck functions