當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript popsicle.request函數代碼示例

本文整理匯總了TypeScript中popsicle.request函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript request函數的具體用法?TypeScript request怎麽用?TypeScript request使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了request函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: analyze

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
				.request(createGetUrl("/spam/detect", "vector", result.toArray()))
				.use(popsicle.plugins.parse("json"))
				.then(response2 => {
					return response2.body;
				});
		});
}
開發者ID:codealphago,項目名稱:word2vec-spam-filter,代碼行數:25,代碼來源:index.ts

示例2: makeRequest

export async function makeRequest (url: string): Promise<Response> {
  const req = request({
    url,
    headers: {
      'User-Agent': 'Scrappy-LinkExpanding 1.0 (+https://github.com/blakeembrey/node-scrappy)'
    },
    use: [],
    transport: createTransport({ type: 'stream', jar: jar() })
  })

  return req.then((res) => {
    // Abort wrapper to ignore streaming errors from aborting (e.g. unzipping).
    function abort () {
      res.body.on('error', () => undefined)
      req.abort()
    }

    return {
      stream: res.body,
      headers: res.headers,
      status: res.status,
      abort: abort,
      url: res.url
    }
  })
}
開發者ID:blakeembrey,項目名稱:node-scrappy,代碼行數:26,代碼來源:support.ts

示例3: createGetUrl

	report: message => {
		return popsicle.request({
			url: createGetUrl("/spam/report"),
			method: "POST",
			body: {
				message
			}
		});
	},
開發者ID:codealphago,項目名稱:word2vec-spam-filter,代碼行數:9,代碼來源:index.ts

示例4: scrapeUrl

export function scrapeUrl (url: string): Promise<Result> {
  const req = request({
    url,
    method: 'get',
    use: [
      plugins.unzip(),
      plugins.headers()
    ],
    options: {
      // Some websites require the use of cookies for their log-in page, so
      // you don't get stuck in an infinite loop (looking at you, NYTimes.com).
      jar: jar()
    }
  })

  return req.then(response => {
    return scrapeStream(url, response.headers, response.body, () => req.abort())
  })
}
開發者ID:abdulhannanali,項目名稱:node-scrappy,代碼行數:19,代碼來源:scrape.ts

示例5: Vector

		.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
				.request(createGetUrl("/spam/detect", "vector", result.toArray()))
				.use(popsicle.plugins.parse("json"))
				.then(response2 => {
					return response2.body;
				});
		});
開發者ID:codealphago,項目名稱:word2vec-spam-filter,代碼行數:20,代碼來源:index.ts

示例6: require

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
			}
		});
	},
	check: message => {
		// go to lower case
		message = message.toLowerCase();

		// split message into words
		const words = normalize(message).split(/\s+/);
開發者ID:codealphago,項目名稱:word2vec-spam-filter,代碼行數:31,代碼來源:index.ts


注:本文中的popsicle.request函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。