NestJS HttpService调用多个端点

问题描述 投票:0回答:1

我通常是一名PHP开发人员,几乎没有使用javascript / typescript的经验。刚开始使用NestJS-我想拥有一个端点,该端点返回通过另一个端点从另一个系统检索的requisitions列表。

粗略的想法:

  1. 使用凭证呼叫登录端点
  2. 使用登录端点中的令牌调用requisition列表端点>
  3. 返回结果
  4. 我已经尝试过像这样调用端点:

const url ='https://the-requisition-endpoint';
const config: AxiosRequestConfig = {
      headers: {
        'Accept': 'application/json',
        'Authorization': 'a_hard_coded_token_string' // hard coded for experimentation
      }
    };
let result = this.httpService.get(url, config);
result.subscribe(response =>
  console.log(response.data);
});

现在,我需要对其进行更改,以便不对令牌进行硬编码-要使用来自登录端点的令牌。

我不确定如何仅在登录端点返回令牌后才强制要求端点。我搜索发现Promise.all()a function called zip might help,但我不知道如何使它起作用。

我通常是一名PHP开发人员,几乎没有使用javascript / typescript的经验。刚开始使用NestJS-我想拥有一个端点,该端点返回从...

typescript axios nestjs
1个回答
0
投票

我相信您要查找的RxJS运算符是zip。本质上,您将需要做这样的事情:

© www.soinside.com 2019 - 2024. All rights reserved.