rxjs - NestJS HttpService - 如何转换响应数据?
问题描述
所以我分别是 NestJS 和 RxJS 的新手,所以我知道这就是我苦苦挣扎的地方。我正在做一个附带项目,目的是了解更多关于两者的信息,所以我对在 HttpService 响应上调用 toPromise() 不感兴趣(我在相关数量的在线示例中看到)。相反,我希望看到如何使用 RxJS 来处理响应。
理想情况下,如果响应成功返回,我想从响应中提取有效负载,并在将其返回给调用者之前稍微修改它。
@Injectable
class TradierService {
constructor(private readonly configService: ConfigService,
private readonly httpService: HttpService) {}
getQuote(symbol: string): Quote {
const query = qs.stringify({ symbols: symbol });
// Obviously has error below
return this.httpService.get<QuotesWrapper>(`/markets/quotes?${query}`, this.getConfig());
}
private getConfig(): AxiosRequestConfig {
return {
baseURL: this.configService.get<string>(TRADIER_BASE_URL),
headers: {
Accept: 'application/json',
Authorization: `Bearer ${this.configService.get<string>(TRADIER_API_KEY)}`
}
};
}
}
解决方案
推荐阅读
- php - php提交的Xss预防
- r - 如何在 R 的数据框中添加新列并使用现有列?
- javascript - Javascript 从嵌套对象构建嵌套对象
- javascript - 从动态创建的表单输入上传多个文件
- python - 从 AVRO 加载到 BigQuery - 在目标表中指定十进制类型
- python - Pandas 加载合格的 .txt 文件,该文件的列值拆分为多行
- python - PyCharm 摆脱 doctest 背景颜色
- anaconda - Conda 环境创建占用了大量空间
- python - 创建一个 c_short_type 数组矩阵
- firebase - FutureBuilder 在 null 上调用了方法“[]”。接收方:空