[英]httpService undefined error when making http request in Nest JS
我正在尝试在我的 Nest JS 应用程序中进行第三方 API 调用。 由于 Nest JS 在引擎盖下使用 Axios 并且在他们的文档中有一个专门的页面https://docs.nestjs.com/techniques/http-module ,我确保遵循文档中提供的实现,但我保留当我尝试通过 Nestjs 的 httpModule 发出 HTTP 请求时遇到 httpService 未定义错误。 我不确定我错过了什么,我试图在这里搜索相关问题,但没有运气。 请帮忙看看,下面是我的代码示例。
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 {}
您使用 @Injectable 装饰器装饰所有使用 Nest.js 的依赖注入功能的类
在这里您可以阅读更多关于依赖注入如何在 Nest.js https 中工作的信息://docs.nestjs.com/providers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.