本文整理汇总了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;未经允许,请勿转载。 |
请发表评论