How to use the @hapi/wreck.get function in @hapi/wreck

To help you get started, we’ve selected a few @hapi/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 hapijs / hapi / test / request.js View on Github external
it('returns not found on internal only route (external)', async () => {

            const server = Hapi.server();
            server.route({
                method: 'GET',
                path: '/some/route',
                options: {
                    isInternal: true,
                    handler: () => 'ok'
                }
            });

            await server.start();
            const err = await expect(Wreck.get('http://localhost:' + server.info.port)).to.reject();
            expect(err.data.res.statusCode).to.equal(404);
            expect(err.data.payload.toString()).to.equal('{"statusCode":404,"error":"Not Found","message":"Not Found"}');
            await server.stop();
        });
github hapijs / hapi / test / core.js View on Github external
it('uses a provided listener with manual listen', async () => {

        const listener = Http.createServer();
        const server = Hapi.server({ listener, autoListen: false });
        server.route({ method: 'GET', path: '/', handler: () => 'ok' });

        const listen = () => {

            return new Promise((resolve) => listener.listen(0, 'localhost', resolve));
        };

        await listen();
        await server.start();
        const { payload } = await Wreck.get('http://localhost:' + server.info.port + '/');
        expect(payload.toString()).to.equal('ok');
        await server.stop();
    });
github hapijs / good / test / monitor.js View on Github external
reporters: {
                    foo: [
                        new Reporters.Namer('foo'),
                        out1
                    ],
                    bar: [
                        out2
                    ]
                }
            });

            await server.start();

            monitor.start();

            const err = await expect(Wreck.get(server.info.uri + '/?q=test')).to.reject();
            expect(err.output.payload.statusCode).to.equal(500);

            await Hoek.wait(50);

            const res1 = out1.data;
            const res2 = out2.data;

            expect(res1).to.have.length(4);
            expect(res1).to.part.contain([{
                event: 'request',
                tags: ['test-tag'],
                data: 'log request data',
                method: 'get',
                path: '/',
                config: { foo: 'bar' },
                name: 'foo'
github hapijs / hapi / test / transmit.js View on Github external
it('returns a gzip response on a get request when accept-encoding: * is requested', async () => {

            const data = '{"test":"true"}';
            const server = Hapi.server({ compression: { minBytes: 1 } });
            server.route({ method: 'GET', path: '/', handler: () => data });
            await server.start();

            const uri = 'http://localhost:' + server.info.port;
            const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': '*' } });
            expect(payload.toString()).to.equal(data);
            await server.stop();
        });
github hapijs / hapi / test / core.js View on Github external
it('refuses to handle new incoming requests on persistent connections', async () => {

            const server = Hapi.server();
            server.route({ method: 'GET', path: '/', handler: () => 'ok' });
            await server.start();

            const agent = new Http.Agent({ keepAlive: true, maxSockets: 1 });
            const first = Wreck.get('http://localhost:' + server.info.port + '/', { agent });
            const second = Wreck.get('http://localhost:' + server.info.port + '/', { agent });

            const { res, payload } = await first;
            const stop = server.stop();

            await expect(second).to.reject();
            await stop;

            expect(res.headers.connection).to.equal('keep-alive');
            expect(payload.toString()).to.equal('ok');
            expect(server._core.started).to.equal(false);
        });
github hapijs / hapi / test / core.js View on Github external
it('refuses to handle new incoming requests on persistent connections', async () => {

            const server = Hapi.server();
            server.route({ method: 'GET', path: '/', handler: () => 'ok' });
            await server.start();

            const agent = new Http.Agent({ keepAlive: true, maxSockets: 1 });
            const first = Wreck.get('http://localhost:' + server.info.port + '/', { agent });
            const second = Wreck.get('http://localhost:' + server.info.port + '/', { agent });

            const { res, payload } = await first;
            const stop = server.stop();

            await expect(second).to.reject();
            await stop;

            expect(res.headers.connection).to.equal('keep-alive');
            expect(payload.toString()).to.equal('ok');
            expect(server._core.started).to.equal(false);
        });
github hapijs / hapi / test / transmit.js View on Github external
++readTimes;
                    if (readTimes > chunkTimes) {
                        return this.push(null);
                    }

                    this.push(block);
                };

                return fileStream;
            };

            const server = Hapi.server();
            server.route({ method: 'GET', path: '/', handler });
            await server.start();

            const { payload } = await Wreck.get('http://localhost:' + server.info.port);
            expect(payload.toString()).to.equal(expectedBody);
            await server.stop();
        });
github hapijs / h2o2 / test / index.js View on Github external
'x-forwarded-host': 'example.com'
            };

            return {
                uri: `http://127.0.0.1:${upstream.info.port}/`,
                headers
            };
        };

        const server = Hapi.server({ host: '127.0.0.1' });
        await server.register(H2o2);

        server.route({ method: 'GET', path: '/', handler: { proxy: { mapUri, xforward: true } } });
        await server.start();

        const response = await Wreck.get('http://127.0.0.1:' + server.info.port + '/');
        expect(response.res.statusCode).to.equal(200);

        const result = JSON.parse(response.payload);

        let expectedClientAddress = '127.0.0.1';
        if (Net.isIPv6(server.listener.address().address)) {
            expectedClientAddress = '::ffff:127.0.0.1';
        }

        expect(result['x-forwarded-for']).to.equal('testhost,' + expectedClientAddress);
        expect(result['x-forwarded-port']).to.equal('1337');
        expect(result['x-forwarded-proto']).to.equal('https');
        expect(result['x-forwarded-host']).to.equal('example.com');

        await upstream.stop();
        await server.stop();
github mark-bradshaw / mrhorse / example / policies / moonInPhase.js View on Github external
const moonInPhase = async (request, h) => {

    const timestamp = parseInt(Date.now() / 1000);
    const url = `http://api.farmsense.net/v1/moonphases/?d=${timestamp}`;
    console.log(`Getting ${url}`);

    const { payload } = await Wreck.get(url, { json: 'force' });
    if (payload[0].Phase !== 'Waning Cresent') {
        throw Boom.forbidden(`${payload[0].Phase} is the wrong moon phase for admin night.`);
    }

    return h.continue;
};

@hapi/wreck

HTTP Client Utilities

BSD-3-Clause
Latest version published 1 month ago

Package Health Score

86 / 100
Full package analysis