本文整理匯總了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+/);