當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript request.default函數代碼示例

本文整理匯總了TypeScript中request.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: request

export function Web3Proxy(req: express.Request, res: express.Response) {
  const { chain, network } = req.params;
  const chainConfig = Config.chainConfig({ chain, network });
  if (chainConfig && chainConfig.rpc) {
    const { host, port } = chainConfig.rpc;
    const url = `http://${host}:${port}`;
    let requestStream;
    if (req.body.jsonrpc) {
      const options = {
        uri: url,
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
        method: req.method,
        body: JSON.stringify(req.body),
        json: true
      };
      requestStream = request(options);
    } else {
      requestStream = req.pipe(request(url));
    }
    requestStream
      .on('error', () => {
        res.status(500).send('An Error Has Occurred');
      })
      .pipe(res);
  } else {
    res.status(500).send(`This node is not configured with a web3 connection for ${chain} ${network} `);
  }
}
開發者ID:bitjson,項目名稱:bitcore,代碼行數:28,代碼來源:index.ts

示例2: getKylinStream

function getKylinStream(API, data, headers) {
  let stream = request({
    method: 'POST',
    uri: API,
    strictSSL: false,
    headers,
    json: true,
    body: data
  });

  let retStream = new Transform({
    objectMode: true,
    transform(chunk, encoding, callback) {
      this.push(chunk);
      callback();
    }
  });

  let processJson = () => {
    // write an empty array to avoid missing first line in csv
    retStream.write([]);

    oboe(stream)
      .on('node', {
        'results.*': (r) => {
          retStream.write(r);
        }
      })
      .on('done', () => {
        retStream.end();
      })
      .on('fail', e => {
        retStream.emit('error', e);
      });
  }

  stream.pause();
  stream.on('response', function(res) {
    if (res.statusCode == 200) {
      processJson();
    } else {
      stream.on('data', (errorBuffer) => {
        let error = "Error happend when getting Kylin result: \n" + errorBuffer.toString();
        try {
          error = JSON.parse(errorBuffer.toString());
        } catch (e) {
          // do nothing
        }
        retStream.emit('error', error);
        retStream.end();
      })
    }
    stream.resume();
  })
  .on('error', function(err) {
    retStream.emit('error', err);
  });

  return retStream;
}
開發者ID:martin-liu,項目名稱:m-sails,代碼行數:60,代碼來源:WrapperService.ts

示例3: meCallback

let updateStore = ((merchant) => {
    console.log("Updating Merchant");

    var options = {
        url: squareBaseURLv1 + "me",
        headers: {
            'Authorization': 'Bearer ' + merchant.access_token,
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    };

    function meCallback(error, response, body) {
        if (!error) {
            var items = JSON.parse(body);
            // console.log(items);
            console.log("Updating " + items.name);
            items.access_token = merchant.access_token;
            items.key = merchant.key;
            updateLocations(items);
        } else {
            console.log("--      Error       --");
            console.log("--                  --");
            console.log(error);
            console.log("--                  --");
            console.log("--                  --");
        }
    }

    request(options, meCallback);

});
開發者ID:devdlx,項目名稱:charlesies-catalog,代碼行數:32,代碼來源:index.ts

示例4: categoriesCallback

let updateCategories = ((merchant, location_id) => {
    console.log("fetching Categories");
    var options = {
        url: squareBaseURLv1 + location_id + "/categories",
        headers: {
            'Authorization': 'Bearer ' + merchant.access_token,
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    };

    function categoriesCallback(error, response, body) {
        // console.log(squareBaseURLv1 + location_id + "/categories");
        if (!error && response.statusCode == 200) {
            var items = JSON.parse(body);
            updateProducts(merchant, location_id, items);
        } else if (error) {
            console.log("--   Error       --");
            console.log("--          --");
            console.log(error);
            console.log("--          --");
            console.log("--          --");
        }
    }

    request(options, categoriesCallback);

});
開發者ID:devdlx,項目名稱:charlesies-catalog,代碼行數:28,代碼來源:index.ts

示例5: getZones

 public getZones(bot: any, message: any) {
     let uri = `http://www.warcraftlogs.com/v1/zones?api_key=${process.env.WCL_PUBLIC_KEY}`;
     console.log(uri);
     var messageArray : string[] = message.content.split(' ');
     request({ method : 'GET', uri: uri, json: true}, (error, response, body) => {
         if(!error && response.statusCode == 200) {
             let zones : Zone[] = response.body;
             if(messageArray.length === 2) {
                 let zoneToSearchFor = messageArray[1].toLocaleUpperCase();
                 let isFound = false;
                 zones.every( (value,index,array) => {
                     if(value.name.toLocaleUpperCase() === zoneToSearchFor || value.name.toLocaleUpperCase().indexOf(zoneToSearchFor) > -1) {
                         console.log(`Found zone user selected`);
                         bot.sendMessage(message.channel, `\`\`\`${prettyjson.render(value)}\`\`\`\n`);
                         isFound = true;
                         return false;
                     }
                     return true;
                 });
                 if(!isFound){
                     bot.sendMessage(message.channel, `Could not find zone with name '${zoneToSearchFor}'`);
                 }
             } else {
                 // all zones
                 bot.sendMessage(message.channel, `\`\`\`${prettyjson.render(zones.map( a => {return `${a.id} :: ${a.name}`;}))}\`\`\`\n`);
             }
         } else {
             bot.sendMessage(message.channel, `\`\`\`${prettyjson.render(body)}\`\`\`\n`);
         }
     });
 }
開發者ID:dellinger,項目名稱:warcraft-rankings-discord-bot,代碼行數:31,代碼來源:WCLActions.ts

示例6: request

 copyPaste.paste((error, content) => {
     if (content.indexOf("http") > -1) {
         request(content, (error, response, body) => {
             convert(body);
         });
     }
 });
開發者ID:GregorBiswanger,項目名稱:Brackets-json2ts,代碼行數:7,代碼來源:extension.ts

示例7: Promise

  return new Promise((resolve, reject) => {
    try {
      let skip = false;
      let _timeout = setTimeout(() => {
        skip = true;
        reject('Error: ETIMEDOUT');
      }, options.timeout);

      request(options, (err, response, body) => {
        log('response');
        log(body);
        if (skip) {
          log('skiped!', err);
          return;
        }
        clearTimeout(_timeout);

        if (err) {
          setImmediate(reject, err);
        }
        else {
          setImmediate(resolve, {response: response, body: body});
        }
      });
    }
    catch (err){
      log('err', err);
      setImmediate(reject, err);
    }
  });
開發者ID:mghayour,項目名稱:Node.js-Telegram-Bot-API,代碼行數:30,代碼來源:1request.ts

示例8: query

    query(index: string, query: string, start?: any, pageSize?: any, cb?: any): void {
        if (typeof start === "function") {
            cb = start;
            start = 0;
            pageSize = 20;
        }
        var url = this.host + "databases/" + this.db + "/indexes/" + index + "?&start=" + start + "&pageSize=" + pageSize + "&query=" + encodeURIComponent(query);
        request(url, (error, response, body) => {
            if (!error && response.statusCode === 200) {
                var result = this.serializer.parse(body);

                var statistics = _.reduce(result, (memo, value, key) => {
                    if (key !== "Results") {
                        memo[key] = value;
                    }
                    return memo;
                }, {});
                result.Results.statistics = statistics;
                if (statistics.IsStale) {
                    setTimeout(() => this.query(index, query, cb), 100);
                } else {
                    cb(null, result.Results);
                }

            } else {
                cb(error || response.statusCode, null);
            }
        });
    }
開發者ID:Antares007,項目名稱:AiPos,代碼行數:29,代碼來源:ravendb.ts

示例9: tryRequest

    function tryRequest(attempt: number) {
        request(methodBody, function (err, apiResponse, apiBody) {
            if (err) {
                if (attempt > KONG_MAX_ATTEMPTS) {
                    error(`kongAction: Giving up after ${KONG_MAX_ATTEMPTS} attempts to send a request to Kong.`);
                    // Still open up calls to Kong again now. Otherwise we would get stuck
                    // in a deadlock loop.
                    _kongAvailable = true;
                    return callback(err);
                }
                warn(`kongAction: Failed to send a request to Kong; retrying in ${KONG_RETRY_DELAY} ms (#${attempt+1}). Preventing other calls in the mean time.`);
                _kongAvailable = false;

                setTimeout(tryRequest, KONG_RETRY_DELAY, attempt + 1);
                return;
            }
            _kongAvailable = true;
            if (expectedStatusCode != apiResponse.statusCode) {
                const err: any = new Error('kongAction ' + method + ' on ' + url + ' did not return the expected status code (got: ' + apiResponse.statusCode + ', expected: ' + expectedStatusCode + ').');
                err.status = apiResponse.statusCode;
                debug(method + ' /' + url);
                debug(methodBody);
                debug(apiBody);
                //console.error(apiBody);
                return callback(err);
            }
            callback(null, getJson(apiBody));
        });
    }
開發者ID:Haufe-Lexware,項目名稱:wicked.portal-kong-adapter,代碼行數:29,代碼來源:utils.ts

示例10: Promise

 return new Promise(function(resolve, reject) {
   console.log(`getting ${url}`);
   request(url, function(err, response, body) {
     console.log(`get ${url} body: ${body}`);
     err && reject(err) || resolve(body);
   });
 });
開發者ID:yedf,項目名稱:wx-rest,代碼行數:7,代碼來源:util2.ts


注:本文中的request.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。