How to use the popsicle.request function in popsicle

To help you get started, we’ve selected a few popsicle 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 ShiftNrg / shift / modules / transport.js View on Github external
}

	peer = library.logic.peers.create(peer);

	var req = {
		url: 'http://' + peer.ip + ':' + peer.port + url,
		method: options.method,
		headers: __private.headers,
		timeout: library.config.peers.options.timeout
	};

	if (options.data) {
		req.body = options.data;
	}

	popsicle.request(req)
		.use(popsicle.plugins.parse(['json'], false))
		.then(function (res) {
			if (res.status !== 200) {
				// Remove peer
				__private.removePeer({peer: peer, code: 'ERESPONSE ' + res.status}, req.method + ' ' + req.url);

				return setImmediate(cb, ['Received bad response code', res.status, req.method, req.url].join(' '));
			} else {
				var headers = peer.applyHeaders(res.headers);

				var report = library.schema.validate(headers, schema.headers);
				if (!report) {
					// Remove peer
					__private.removePeer({peer: peer, code: 'EHEADERS'}, req.method + ' ' + req.url);

					return setImmediate(cb, ['Invalid response headers', JSON.stringify(headers), req.method, req.url].join(' '));
github doodyparizada / word2vec-spam-filter / webclient / scripts / src / index.ts View on Github external
import * as view from "./page";

const popsicle = require("popsicle");
const shuffle = require("shuffle-array");
const baseUrl = "http://localhost:5000";

const dictionary = {} as { [word: string]: number };
let dictionarySize;
popsicle.request(createGetUrl("/words/list")).then(res => {
	res.body.split("\n").forEach((word, index) => dictionary[word] = index);
	dictionarySize = Object.keys(dictionary).length;
	console.log(`words loaded (count of ${ dictionarySize })`);
});

const main = document.getElementById("main");
view.render(main, {
	report: message => {
		return popsicle.request({
			url: createGetUrl("/spam/report"),
			method: "POST",
			body: {
				message
			}
		});
	},
github VadimDez / ng2-pdf-viewer / node_modules / popsicle-proxy-agent / dist / index.spec.js View on Github external
t.test('support no proxy', function (t) {
        return popsicle_1.request(server.url())
            .use(proxy({ proxy: proxyServer.url(), noProxy: url_1.parse(server.url()).hostname }))
            .then(function (res) {
            t.equal(res.status, 200);
            t.equal(res.body, 'server /');
        });
    });
    t.test('after', function (t) {
github SwellRT / swellrt / pad / node_modules / typings / node_modules / typings-core / node_modules / popsicle-proxy-agent / dist / index.spec.js View on Github external
t.test('use proxy option', function (t) {
        var proxy = createProxy({
            proxy: proxyServer.url()
        });
        return popsicle_1.request({
            url: server.url(),
            transport: popsicle_1.createTransport({
                agent: proxy(server.url())
            })
        })
            .then(function (res) {
            t.equal(res.status, 200);
            t.equal(res.body, 'proxy ' + server.url());
        });
    });
    t.test('support no proxy', function (t) {
github doodyparizada / word2vec-spam-filter / webclient / scripts / src / im-sender.tsx View on Github external
private send() {
		popsicle.request({
			url: createGetUrl("/messages"),
			method: "POST",
			body: {
				message: this.textarea.value
			}
		}).then(res => console.log("message sent"));
	}
github blakeembrey / node-htmlmetaparser / scripts / fixtures.js View on Github external
function fetch () {
    console.log('Fetching "' + fixtureUrl + '"...')

    return popsicle.request({
      url: fixtureUrl,
      transport: popsicle.createTransport({
        type: 'buffer',
        jar: popsicle.jar(),
        maxBufferSize: 20 * 1000 * 1000
      })
    })
      .then(function (res) {
        return mkdir(dir)
          .then(function () {
            console.log('Writing "' + filename + '"...')

            const meta = {
              originalUrl: fixtureUrl,
              url: res.url,
              headers: res.headers,
github doodyparizada / word2vec-spam-filter / webclient / scripts / src / index.ts View on Github external
function analyze(indexes: number[], reals: number[]): Promise<{ spam: boolean; confidence: number; }> {
	return popsicle
		.request(createGetUrl("/words/vector", "ids", indexes))
		.use(popsicle.plugins.parse("json"))
		.then(response => {
			let result: Vector = null;

			reals.forEach(index => {
				let vector = new Vector(response.body.words[index].vector);

				if (result === null) {
					result = vector;
				} else {
					result.add(vector);
				}
			});

			return popsicle
github RiseVision / rise-node / packages / core-p2p / src / transport.ts View on Github external
(retry) =>
          popsicle
            .request(req)
            .use(parsingPlugin)
            .catch(retry),
        {
github crypti / eth-price / index.js View on Github external
module.exports = toSymbol => {
	if (typeof toSymbol === 'string') {
		toSymbol = toSymbol.toUpperCase();
	} else {
		toSymbol = 'USD';
	}

	return popsicle.request({
		method: 'POST',
		url: 'https://min-api.cryptocompare.com/data/price',
		query: {
			fsym: 'ETH',
			tsyms: toSymbol
		}
	})
		.use(popsicle.plugins.parse(['json']))
		.then(resp => resp.body)
		.then(data => {
			const symbols = Object.keys(data);

			return symbols
				.map(symbol => `${symbol}: ${data[symbol]}`);
		});
};
github doodyparizada / word2vec-spam-filter / webclient / scripts / src / im-receiver.tsx View on Github external
private poll() {
		popsicle
			.request(`${ baseUrl }/messages`)
			.use(popsicle.plugins.parse("json"))
			.then(res => {
				if (res.body.message) {
					const id = generateMessageId();

					this.setState({
						messages: [{ id, content: res.body.message }].concat(this.state.messages)
					});

					setTimeout(() => {
						this.props.check(res.body.message).then(res => {
							this.updateMessageState(id, res.spam);
						});
					}, 2500);
				}