本文整理匯總了TypeScript中request.get函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript get函數的具體用法?TypeScript get怎麽用?TypeScript get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了get函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should be able to send 406', (done) => {
request.get('http://localhost:5674/errors/notacceptable', function(error, response, body) {
expect(response.statusCode).to.eq(406);
done();
});
});
示例2: getAComic
// para: ids:string - id of comic, callback:function(error:string, response:string, body:string) => void - callback with a three string parameters
// Given a comic id, get the associated JSON comic object from the database
// return: none
getAComic(comicId:string, callback:(error:string, response:string, body:string) => void) {
var request = require('request');
request.get('http://glacial-retreat-45891.herokuapp.com/comic/' + comicId, callback);
return;
}
示例3: it
it('has a working index page with SSL', done => {
request.get({url: 'https://localhost:5001', rejectUnauthorized: false}, (error, response, body) => {
expect(response.statusCode).to.equal(200);
done();
});
});
示例4: Client
const pubKey = Bitcore.PrivateKey(tmp).toPublicKey() ;
const baseUrl = `https://api.bitcore.io/api/${coin}/${network}`;
let client = new Client({
baseUrl,
authKey: authKeyObj,
});
// utxos
// addresses
const url = `${baseUrl}/wallet/${pubKey}/${path}`;
console.log('[v8tool.37:url:]', url);
const signature = client.sign({ method: 'GET', url });
const payload = {};
request.get(url, {
headers: { 'x-signature': signature },
body: payload,
json: true
}, (err, req, body) => {
if (err) {
console.log('[v8tool.43:err:]', err);
} else {
try {
console.log('[v8tool.50:body:]', body);
} catch (e) {
console.log('[v8tool.52]', e, body);
}
}
});
示例5: function
module.exports = function (callback) {
const eventsUrl = `${firebaseConfig.databaseURL}/events.json?auth=${FirebaseAppSecret}`;
const stateUrl = `${firebaseConfig.databaseURL}/state.json?auth=${FirebaseAppSecret}`;
const maxWebtaskDuration = 25000;
const interval = 1000;
const newOrderChance = 0.3;
var executionCount = maxWebtaskDuration / interval;
request.get(stateUrl, getStateCallback);
function getStateCallback(error, res, stateBody) {
if (error) {
callback(error);
} else if (res.statusCode !== 200) {
callback(res.body.error);
} else {
const state: ScreenState = JSON.parse(stateBody);
generateOrders(state);
}
}
function generateOrders(state: ScreenState) {
scheduleGenerateOrder();
function generateOrder() {
const event = Math.random() > newOrderChance
? randomCounteroffer()
: randomOrder();
const requestOptions = {
method: 'POST',
url: eventsUrl,
json: event
};
request(requestOptions, scheduleGenerateOrder);
}
function randomCounteroffer() {
console.log('Will add counteroffer');
const index = randomInt(0, state.activeOrders.length - 1);
const order = state.activeOrders[index];
return {
type: "AddOrderAction",
user: "Market Maker",
product: order.product,
quantity: 1,
price: order.price,
direction: 1 - order.direction,
timestamp: { '.sv': 'timestamp' }
};
}
function randomOrder() {
console.log('Will add new order');
return {
type: "AddOrderAction",
user: "Market Maker",
product: ['crystals', 'credits', 'mithril', 'mercury'][randomInt(0, 5)],
quantity: randomInt(1, 1000),
price: randomInt(1, 1000),
direction: randomInt(0, 2) + 0,
timestamp: { '.sv': 'timestamp' }
};
}
function scheduleGenerateOrder() {
if (executionCount-- > 0) {
console.log(`Scheduling new order. ${executionCount} remaining.`);
setTimeout(generateOrder, interval);
} else {
console.log('Sequence finished');
callback(null, 'Finished');
}
}
}
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
}
示例6: getAllUsers
// para: callback:function(error:string, response:string, body:string) => void - callback with a three string parameters
// retrieve every single user in the mongo user database
// return: none
getAllUsers(callback:(error:string, response:string, body:string) => void) {
var request = require('request');
request.get('http://charbroiled-user-api.herokuapp.com/user/', callback);
return;
}