当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript request.defaults函数代码示例

本文整理汇总了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);
    });
  });
}
开发者ID:mattzeunert,项目名称:fromjs,代码行数:12,代码来源:ProxyInstrumenter.test.ts

示例2: constructor

 constructor(cookieJar:CookieJar) {
     this.requestWithJar = request.defaults({jar: cookieJar});
 }
开发者ID:SwadicalRag,项目名称:skyweb,代码行数:3,代码来源:status_service.ts

示例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;
开发者ID:relution-io,项目名称:relution-sdk,代码行数:31,代码来源:http.ts

示例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);
            }
        })
    })
开发者ID:hellopao,项目名称:koa2-middlewares,代码行数:31,代码来源:index.ts

示例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 = {
开发者ID:tpennetta,项目名称:neo4j-typescript,代码行数:31,代码来源:index.ts

示例6: constructor

 public constructor(logger: ILogger) {
     super();
     this.logger = logger;
     this.cookieJar = Request.jar();
     this.request = Request.defaults({ jar: this.cookieJar });
 }
开发者ID:anurse,项目名称:SignalR,代码行数:6,代码来源:NodeHttpClient.ts


注:本文中的request.defaults函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。