本文整理匯總了TypeScript中request.defaults函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript defaults函數的具體用法?TypeScript defaults怎麽用?TypeScript defaults使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了defaults函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: makeRequest
function makeRequest(path, headers = {}) {
const r = request.defaults({ proxy: "http://127.0.0.1:" + proxyPort });
return new Promise(resolve => {
r({ url: "http://localhost:" + port + path, headers }, function(
error,
response,
body
) {
resolve(body);
});
});
}
示例2: constructor
constructor(cookieJar:CookieJar) {
this.requestWithJar = request.defaults({jar: cookieJar});
}
示例3:
import * as diag from '../core/diag';
import * as http from 'http';
import * as init from '../core/init';
import * as offline from './offline';
import * as request from 'request';
import * as roles from '../security/roles';
import * as server from '../security/server';
import * as urls from './urls';
// require request.js to manage cookies for us
let requestDefaults = {
json: true,
jar: true,
withCredentials: true
};
let requestWithDefaults = request.defaults(requestDefaults);
/**
* callback allowing customizing an object not immediately available at time of call.
*
* @param object for inspection or customization.
* @return promise or object on same deferred object.
*/
export interface HttpCallback<T> {
(value: T): Q.Promise<T> | T;
}
/**
* type representing a raw request.
*/
export type HttpRequest = request.Request;
示例4: Promise
"use strict";
import * as request from "request";
import * as cheerio from "cheerio";
const KOA_MIDDLEWARES_PAGE = "https://github.com/koajs/koa/wiki";
const KOA_MIDDLEWARES_DEFINITION = "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/";
const http = request.defaults({
headers: {
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36"
}
});
export function getKoa2Middlewares (): PromiseLike<string[]> {
return new Promise((resolve, reject) => {
http.get(KOA_MIDDLEWARES_PAGE, (err, res, body) => {
if (err) {
reject(err);
} else {
const $ = cheerio.load(body);
const middlewares = Array.from($('td[align="center"]'))
.filter(node => $(node).html() !== "")
.map(node => {
return $(node).prev().find('a').html()
});
resolve(middlewares);
}
})
})
示例5:
* TODO: Don't reuse the same instance fo requestOptions for each call.
*/
import * as path from "path";
import * as url from "url";
import * as request from "request";
import * as util from "util";
import * as http from "http";
//==============================================================================
// Global request module defaults.
//==============================================================================
request.defaults({
headers: {
"Content-Type": "application/json"
}
});
//==============================================================================
// Global constants.
//==============================================================================
export enum NEO4J_PROTOCOL { http, https };
// TODO: Change to enums
const NEO4J_ENTITY_TYPES: string[] = ["node", "relationship"];
const NEO4J_HTTP_METHODS: string[] = ["DELETE", "GET", "POST", "PUT"];
const NEO4J_RELATIONSHIP_DIRECTION: string[] = ["all", "in", "out"];
const NEO4J_STANDARD_PATHS: any = {
示例6: constructor
public constructor(logger: ILogger) {
super();
this.logger = logger;
this.cookieJar = Request.jar();
this.request = Request.defaults({ jar: this.cookieJar });
}