本文整理汇总了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 });
}