本文整理汇总了TypeScript中request.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: request
export function Web3Proxy(req: express.Request, res: express.Response) {
const { chain, network } = req.params;
const chainConfig = Config.chainConfig({ chain, network });
if (chainConfig && chainConfig.rpc) {
const { host, port } = chainConfig.rpc;
const url = `http://${host}:${port}`;
let requestStream;
if (req.body.jsonrpc) {
const options = {
uri: url,
headers: { 'content-type': 'application/x-www-form-urlencoded' },
method: req.method,
body: JSON.stringify(req.body),
json: true
};
requestStream = request(options);
} else {
requestStream = req.pipe(request(url));
}
requestStream
.on('error', () => {
res.status(500).send('An Error Has Occurred');
})
.pipe(res);
} else {
res.status(500).send(`This node is not configured with a web3 connection for ${chain} ${network} `);
}
}
开发者ID:bitjson,项目名称:bitcore,代码行数:28,代码来源:index.ts
示例2: getKylinStream
function getKylinStream(API, data, headers) {
let stream = request({
method: 'POST',
uri: API,
strictSSL: false,
headers,
json: true,
body: data
});
let retStream = new Transform({
objectMode: true,
transform(chunk, encoding, callback) {
this.push(chunk);
callback();
}
});
let processJson = () => {
// write an empty array to avoid missing first line in csv
retStream.write([]);
oboe(stream)
.on('node', {
'results.*': (r) => {
retStream.write(r);
}
})
.on('done', () => {
retStream.end();
})
.on('fail', e => {
retStream.emit('error', e);
});
}
stream.pause();
stream.on('response', function(res) {
if (res.statusCode == 200) {
processJson();
} else {
stream.on('data', (errorBuffer) => {
let error = "Error happend when getting Kylin result: \n" + errorBuffer.toString();
try {
error = JSON.parse(errorBuffer.toString());
} catch (e) {
// do nothing
}
retStream.emit('error', error);
retStream.end();
})
}
stream.resume();
})
.on('error', function(err) {
retStream.emit('error', err);
});
return retStream;
}
开发者ID:martin-liu,项目名称:m-sails,代码行数:60,代码来源:WrapperService.ts
示例3: meCallback
let updateStore = ((merchant) => {
console.log("Updating Merchant");
var options = {
url: squareBaseURLv1 + "me",
headers: {
'Authorization': 'Bearer ' + merchant.access_token,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};
function meCallback(error, response, body) {
if (!error) {
var items = JSON.parse(body);
// console.log(items);
console.log("Updating " + items.name);
items.access_token = merchant.access_token;
items.key = merchant.key;
updateLocations(items);
} else {
console.log("-- Error --");
console.log("-- --");
console.log(error);
console.log("-- --");
console.log("-- --");
}
}
request(options, meCallback);
});
开发者ID:devdlx,项目名称:charlesies-catalog,代码行数:32,代码来源:index.ts
示例4: categoriesCallback
let updateCategories = ((merchant, location_id) => {
console.log("fetching Categories");
var options = {
url: squareBaseURLv1 + location_id + "/categories",
headers: {
'Authorization': 'Bearer ' + merchant.access_token,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};
function categoriesCallback(error, response, body) {
// console.log(squareBaseURLv1 + location_id + "/categories");
if (!error && response.statusCode == 200) {
var items = JSON.parse(body);
updateProducts(merchant, location_id, items);
} else if (error) {
console.log("-- Error --");
console.log("-- --");
console.log(error);
console.log("-- --");
console.log("-- --");
}
}
request(options, categoriesCallback);
});
开发者ID:devdlx,项目名称:charlesies-catalog,代码行数:28,代码来源:index.ts
示例5: getZones
public getZones(bot: any, message: any) {
let uri = `http://www.warcraftlogs.com/v1/zones?api_key=${process.env.WCL_PUBLIC_KEY}`;
console.log(uri);
var messageArray : string[] = message.content.split(' ');
request({ method : 'GET', uri: uri, json: true}, (error, response, body) => {
if(!error && response.statusCode == 200) {
let zones : Zone[] = response.body;
if(messageArray.length === 2) {
let zoneToSearchFor = messageArray[1].toLocaleUpperCase();
let isFound = false;
zones.every( (value,index,array) => {
if(value.name.toLocaleUpperCase() === zoneToSearchFor || value.name.toLocaleUpperCase().indexOf(zoneToSearchFor) > -1) {
console.log(`Found zone user selected`);
bot.sendMessage(message.channel, `\`\`\`${prettyjson.render(value)}\`\`\`\n`);
isFound = true;
return false;
}
return true;
});
if(!isFound){
bot.sendMessage(message.channel, `Could not find zone with name '${zoneToSearchFor}'`);
}
} else {
// all zones
bot.sendMessage(message.channel, `\`\`\`${prettyjson.render(zones.map( a => {return `${a.id} :: ${a.name}`;}))}\`\`\`\n`);
}
} else {
bot.sendMessage(message.channel, `\`\`\`${prettyjson.render(body)}\`\`\`\n`);
}
});
}
开发者ID:dellinger,项目名称:warcraft-rankings-discord-bot,代码行数:31,代码来源:WCLActions.ts
示例6: request
copyPaste.paste((error, content) => {
if (content.indexOf("http") > -1) {
request(content, (error, response, body) => {
convert(body);
});
}
});
开发者ID:GregorBiswanger,项目名称:Brackets-json2ts,代码行数:7,代码来源:extension.ts
示例7: Promise
return new Promise((resolve, reject) => {
try {
let skip = false;
let _timeout = setTimeout(() => {
skip = true;
reject('Error: ETIMEDOUT');
}, options.timeout);
request(options, (err, response, body) => {
log('response');
log(body);
if (skip) {
log('skiped!', err);
return;
}
clearTimeout(_timeout);
if (err) {
setImmediate(reject, err);
}
else {
setImmediate(resolve, {response: response, body: body});
}
});
}
catch (err){
log('err', err);
setImmediate(reject, err);
}
});
开发者ID:mghayour,项目名称:Node.js-Telegram-Bot-API,代码行数:30,代码来源:1request.ts
示例8: query
query(index: string, query: string, start?: any, pageSize?: any, cb?: any): void {
if (typeof start === "function") {
cb = start;
start = 0;
pageSize = 20;
}
var url = this.host + "databases/" + this.db + "/indexes/" + index + "?&start=" + start + "&pageSize=" + pageSize + "&query=" + encodeURIComponent(query);
request(url, (error, response, body) => {
if (!error && response.statusCode === 200) {
var result = this.serializer.parse(body);
var statistics = _.reduce(result, (memo, value, key) => {
if (key !== "Results") {
memo[key] = value;
}
return memo;
}, {});
result.Results.statistics = statistics;
if (statistics.IsStale) {
setTimeout(() => this.query(index, query, cb), 100);
} else {
cb(null, result.Results);
}
} else {
cb(error || response.statusCode, null);
}
});
}
开发者ID:Antares007,项目名称:AiPos,代码行数:29,代码来源:ravendb.ts
示例9: tryRequest
function tryRequest(attempt: number) {
request(methodBody, function (err, apiResponse, apiBody) {
if (err) {
if (attempt > KONG_MAX_ATTEMPTS) {
error(`kongAction: Giving up after ${KONG_MAX_ATTEMPTS} attempts to send a request to Kong.`);
// Still open up calls to Kong again now. Otherwise we would get stuck
// in a deadlock loop.
_kongAvailable = true;
return callback(err);
}
warn(`kongAction: Failed to send a request to Kong; retrying in ${KONG_RETRY_DELAY} ms (#${attempt+1}). Preventing other calls in the mean time.`);
_kongAvailable = false;
setTimeout(tryRequest, KONG_RETRY_DELAY, attempt + 1);
return;
}
_kongAvailable = true;
if (expectedStatusCode != apiResponse.statusCode) {
const err: any = new Error('kongAction ' + method + ' on ' + url + ' did not return the expected status code (got: ' + apiResponse.statusCode + ', expected: ' + expectedStatusCode + ').');
err.status = apiResponse.statusCode;
debug(method + ' /' + url);
debug(methodBody);
debug(apiBody);
//console.error(apiBody);
return callback(err);
}
callback(null, getJson(apiBody));
});
}
开发者ID:Haufe-Lexware,项目名称:wicked.portal-kong-adapter,代码行数:29,代码来源:utils.ts
示例10: Promise
return new Promise(function(resolve, reject) {
console.log(`getting ${url}`);
request(url, function(err, response, body) {
console.log(`get ${url} body: ${body}`);
err && reject(err) || resolve(body);
});
});
开发者ID:yedf,项目名称:wx-rest,代码行数:7,代码来源:util2.ts
注:本文中的request.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论