How to use wreck - 10 common examples

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 mtharrison / hapi.js-in-action / test / CH02.js View on Github external
serves: 16,
                    cuisine: 'Mongolian',
                    ingredients: 'Cheese',
                    directions: 'Melt'
                };

                const options = {
                    payload: JSON.stringify(recipe),
                    headers: {
                        'content-type': 'application/json'
                    }
                };

                // No-authentication

                Wreck.post('http://localhost:4000/api/recipes', options, (err, res, payload) => {

                    expect(err).to.not.exist();
                    expect(res.statusCode).to.equal(401);

                    // With authentication

                    options.headers.Authorization = 'Bearer q8lrh5rzkrzdi4un8kfza5y3k1nn184x';

                    Wreck.post('http://localhost:4000/api/recipes', options, (err, res, payload) => {

                        expect(err).to.not.exist();
                        expect(res.statusCode).to.equal(200);

                        Wreck.get('http://localhost:4000/api/recipes?cuisine=Mongolian', (err, res, payload) => {

                            expect(err).to.not.exist();
github fishin / ficion / queue.js View on Github external
Wreck.get(url + '/job/byname/' + projects[i], { json: true }, function(err1, resp1, payload1) {

            var jobId = payload1.id;
            var payload = { jobId: jobId };
            var options = {
                payload: JSON.stringify(payload),
                json: true
            };
//            console.log(options);
            Wreck.post(url + '/queue', options, function(err2, resp2, payload2) {
                if (payload2 && payload2.statusCode) {
                    console.log(payload2);
                };
                iterate(i + 1);
            });
        });
    }
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 mtharrison / hapi.js-in-action / test / CH03.js View on Github external
const options = {
                            headers: {
                                cookie: res.headers['set-cookie'][0].split(';')[0]
                            },
                            payload: JSON.stringify({
                                name: 'Web test',
                                cooking_time: '12 mins',
                                prep_time: '15 mins',
                                serves: 16,
                                cuisine: 'Mongolian',
                                ingredients: 'Cheese',
                                directions: 'Melt'
                            })
                        };

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

                            expect(err).to.not.exist();
                            expect(res.statusCode).to.equal(302);
                            expect(res.headers.location).to.equal('http://localhost:4000');

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

                                expect(err).to.not.exist();
                                expect(res.statusCode).to.equal(200);
                                expect(payload.toString()).to.include('Web test');
                                cleanup(child, done);
                            });
                        });
                    });
                });
github mtharrison / hapi.js-in-action / test / CH09.js View on Github external
throw err;
                    }

                    let cookie = res.headers['set-cookie'][0].split(';')[0];
                    expect(payload.toString()).to.include('Feeling great!');

                    let options = {
                        headers: {
                            cookie: cookie
                        },
                        payload: JSON.stringify({
                            message: 'Something else'
                        })
                    };

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

                        if (err) {
                            throw err;
                        }

                        cookie = res.headers['set-cookie'][0].split(';')[0];

                        options = {
                            headers: {
                                cookie: cookie
                            }
                        };

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

                            if (err) {
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 hapijs / hapi / test / gzip.js View on Github external
it('returns a gzip response on a post request when accept-encoding: gzip is requested', function (done) {

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

            expect(err).to.not.exist;
            expect(body).to.equal(zdata);
            done();
        });
    });

wreck

HTTP Client Utilities

BSD-3-Clause
Latest version published 6 years ago

Package Health Score

56 / 100
Full package analysis

Popular wreck functions