當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。