我试图在我的Nest JS应用程序中进行第三方API调用。由于Nest JS在其文档https://docs.nestjs.com/techniques/http-module中使用了Axios,并且在其文档中有一个专用页面,所以我确保按照文档提供的实现来执行,但是当我试图从Nestjs通过httpService未定义的错误通过httpModule发出请求时,我仍然会遇到错误。我不知道我错过了什么,我试图在这里寻找相关的问题,但没有运气。请帮忙看一看,下面是我的代码示例。
bankVerification.service.ts
import { HttpService } from '@nestjs/common';
import { Observable } from 'rxjs';
import { config } from 'dotenv';
import { AxiosResponse } from 'axios';
config();
export class BankVerificationService {
constructor(private httpService: HttpService){}
getBanks(countryCode): Observable<AxiosResponse<any>> {
console.log(this.httpService, '===============')
return this.httpService.get(`https://api.flutterwave.com/v3/banks/${countryCode}`, {
headers: {
Authorization: `Bearer ${process.env.FLUTTERWAVE_TEST_SECRET}`
}
});
}
}
下面是我对Axios的HTTP模块配置
import { Module, HttpModule } from '@nestjs/common';
import { BankVerificationService } from '../payment/utils/bankVerification.service';
@Module({
imports: [HttpModule.register({
timeout: 3000,
})],
providers: [BankVerificationService],
})
export class ExternalHttpRequestModule {}
下面是我得到的错误的屏幕截图
发布于 2020-06-23 11:46:55
使用使用Nest.js的依赖项注入特性的@Injectable装饰器装饰所有类
在这里,您可以了解更多关于依赖注入如何在Nest.js https://docs.nestjs.com/providers中工作的内容。
https://stackoverflow.com/questions/62533114
复制相似问题