Reputation: 145
I am trying to make a third-party API call in my Nest JS app. Since Nest JS uses Axios under the hood and has a dedicated page for it in their doc here https://docs.nestjs.com/techniques/http-module, I made sure to follow the implementation as provided on the doc but I keep running into httpService undefined error when I tried to make the HTTP request through the httpModule from Nestjs. I am not sure what I am missing and I've tried to search for the related issue here but with no luck. Kindly help take a look, below is a sample of my code.
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}`
}
});
}
}
Below is my HTTP module config for Axios
import { Module, HttpModule } from '@nestjs/common';
import { BankVerificationService } from '../payment/utils/bankVerification.service';
@Module({
imports: [HttpModule.register({
timeout: 3000,
})],
providers: [BankVerificationService],
})
export class ExternalHttpRequestModule {}
Below is the screenshot of the error I'm getting
Upvotes: 2
Views: 6509
Reputation: 251
You decorate all classes with @Injectable decorator that are using Dependency Injection feature of Nest.js
here you can read more about how Dependency Injection works in Nest.js https://docs.nestjs.com/providers
Upvotes: 13