本文整理汇总了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;
});
});
}
示例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
}
})
}
示例3: createGetUrl
report: message => {
return popsicle.request({
url: createGetUrl("/spam/report"),
method: "POST",
body: {
message
}
});
},
示例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())
})
}
示例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;
});
});
示例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+/);