
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
@betsys-nestjs/http-client
Advanced tools
@betsys-nestjs/http-client
This is a simple wrapper module built around @nestjs/axios.
Package | Version |
---|---|
@nestjs/common | ^10.0.0 |
@nestjs/core | ^10.0.0 |
reflect-metadata | <1.0.0 |
rxjs | ^7.0.0 |
@nestjs/axios | ^3.0.0 |
axios | ^1.0.0 |
The basic usage is similar to the @nestjs/axios module.
You use the HttpClientService
to make HTTP requests.
@Injectable()
export class CatsService {
constructor(private httpService: HttpClientService) {}
findAll(): Observable<AxiosResponse<Cat[]>> {
return this.httpService.get('http://localhost:3000/cats');
}
}
You need to import HttpClient
module to use the HttpClientService
. Both register
and registerAsync
are available:
@Module({
imports: [
HttpModule.register({
timeout: 5000,
maxRedirects: 5,
}),
],
providers: [CatsService],
})
export class CatsModule {}
The library is ready to work with monitoring and logger. To enable it you need to implement your own monitoring and logger service based on abstraction provided by this library.
Time monitoring - used for monitoring of request time, your provided service must implement HttpClientTimeMonitoringInterface
. Implementation of startTimerHttpRequestTime
starts your custom timer returning a function which stops the timer.
Example of time monitoring using @betsys-nestjs/monitoring:
import { Injectable } from '@nestjs/common';
import {
Histogram,
InjectMonitoringConfig,
InjectMonitoringRegistry,
MonitoringConfig,
Registry,
AbstractMonitoringService, exponentialBuckets,
} from '@betsys-nestjs/monitoring';
@Injectable()
export class MonitoringService extends AbstractMonitoringService {
private readonly requestTime: Histogram<string>;
constructor(
@InjectMonitoringConfig() private readonly config: MonitoringConfig,
@InjectMonitoringRegistry() protected readonly registry: Registry,
) {
super(registry);
this.requestTime = this.createMetric(Histogram, {
name: config.getMetricsName('http_client'),
help: 'Histogram of http request times',
buckets: exponentialBuckets(0.001, 2, 20),
labelNames: ['url', 'statusCode', 'api'],
registers: [registry],
});
}
startTimerHttpRequestTime(url: string): ({ statusCode }: { statusCode: number }) => number {
return this.requestTime.startTimer({ url, api: 'api/v1/test' });
}
}
Similar to monitoring you can simply implement custom service following HttpClientLoggerInterface
.
In additional to params accepted by @nestjs/axios
module, you can define if logging should be enabled, and you can choose from two logging levels:
HttpClientLogLevel.Info
, logs basic request and response informationHttpClientLogLevel.Full
, logs detailed request and response information (including headers, body, etc.)To start using Logger or Monitoring service, you simply insert class references to register
or registerAsync
method of HttpClientModule like this:
import { HttpClientModule } from '@betsys-nestjs/http-client';
import { Logger } from '@betsys-nestjs/logger';
import { MonitoringService } from '...'; // the path to the monitoring service implementation
@Module({
imports: [
HttpClientModule.register({
log: true, // default true
logLevel: HttpClientLogLevel.Info, // default 'HttpClientLogLevel.Info'
logger: Logger,
monitoring: MonitoringService,
}),
],
providers: [CatsService],
})
export class CatsModule {}
FAQs
HTTP client for NestJS applications
The npm package @betsys-nestjs/http-client receives a total of 2 weekly downloads. As such, @betsys-nestjs/http-client popularity was classified as not popular.
We found that @betsys-nestjs/http-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.