Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@byndyusoft/nest-http-client
Advanced tools
axios for NestJS
@nestjs/axios
axios
with interceptors and different configs for various clientsendpoint
requests like @octokit/endpoint
yarn add @byndyusoft/nest-http-client @nestjs/common axios
import { TRegisterAsyncOptions } from "@byndyusoft/nest-dynamic-module";
import {
HttpClientModule,
IHttpClientOptions,
} from "@byndyusoft/nest-http-client";
import { DynamicModule, Global, Module } from "@nestjs/common";
import urlJoin from "proper-url-join";
import qs from "qs";
import { UsersClient } from "./usersClient";
@Global()
@Module({
providers: [UsersClient],
exports: [UsersClient],
})
export class ClientModule {
public static registerAsync(
options?: TRegisterAsyncOptions<IHttpClientOptions>,
): DynamicModule {
return HttpClientModule.registerClientModule(
{ module: ClientModule },
options,
(config) => ({
...config,
baseURL: urlJoin(config?.baseURL as string, "/api/v1"),
paramsSerializer: (params) =>
qs.stringify(params, {
skipNulls: true,
arrayFormat: "repeat",
}),
}),
);
}
}
import { Module } from "@nestjs/common";
import axios from "axios";
import { UsersClientModule } from "./clients/users";
import { ConfigModule } from "./configModule";
import { ConfigDto } from "./dtos";
import { SomeService } from "./some.service";
import { SomeController } from "./someController";
const axiosInstance = axios.create();
// You can configure axios here, e.g. interceptors
@Module({
imports: [
ConfigModule.forRoot(),
UsersClientModule.registerAsync({
inject: [ConfigDto],
useFactory: async (config: ConfigDto) => ({
axios: axiosInstance,
config: config.usersApiClient,
}),
}),
],
controllers: [SomeController],
providers: [SomeService],
})
export class AppModule {}
import { HttpClient } from "@byndyusoft/nest-http-client";
import { Injectable } from "@nestjs/common";
import {
CreateUserDto,
ListUsersQueryDto,
ListUsersResponseDto,
ParamsWithUserIdDto,
QueryWithUserVersionDto,
UpdateUserDto,
UserDto,
} from "ᐸDtosᐳ";
@Injectable()
export class UsersClient {
public constructor(private readonly httpClient: HttpClient) {}
public createUser(request: CreateUserDto): Promise<UserDto> {
return this.httpClient.endpoint("POST /users", request);
}
public deleteUser(
request: ParamsWithUserIdDto & QueryWithUserVersionDto,
): Promise<UserDto> {
return this.httpClient.endpoint(
"DELETE /users/{userId}{?userVersion}",
request,
);
}
public getUserById(request: ParamsWithUserIdDto): Promise<UserDto> {
return this.httpClient.endpoint("GET /users/{userId}", request);
}
public listUsers(
request?: Partial<ListUsersQueryDto>,
): Promise<ListUsersResponseDto> {
return this.httpClient.endpoint("GET /users", request);
}
public updateUser(
request: ParamsWithUserIdDto & QueryWithUserVersionDto & UpdateUserDto,
): Promise<UserDto> {
return this.httpClient.endpoint(
"PATCH /users/{userId}{?userVersion}",
request,
);
}
}
import { HttpClient } from "@byndyusoft/nest-http-client";
import { Injectable } from "@nestjs/common";
import _ from "lodash";
import {
CreateUserDto,
ListUsersQueryDto,
ListUsersResponseDto,
ParamsWithUserIdDto,
QueryWithUserVersionDto,
UpdateUserDto,
UserDto,
} from "ᐸDtosᐳ";
@Injectable()
export class UsersClient {
public constructor(private readonly httpClient: HttpClient) {}
public createUser(request: CreateUserDto): Promise<UserDto> {
return this.httpClient.post("/users", request);
}
public deleteUser(
request: ParamsWithUserIdDto & QueryWithUserVersionDto,
): Promise<UserDto> {
return this.httpClient.delete(
`/users/${encodeURIComponent(request.userId)}`,
{
params: _.omit(request, "userId"),
},
);
}
public getUserById(request: ParamsWithUserIdDto): Promise<UserDto> {
return this.httpClient.get(`/users/${encodeURIComponent(request.userId)}`);
}
public listUsers(
request?: Partial<ListUsersQueryDto>,
): Promise<ListUsersResponseDto> {
return this.httpClient.get("/users", {
params: request,
});
}
public updateUser(
request: ParamsWithUserIdDto & QueryWithUserVersionDto & UpdateUserDto,
): Promise<UserDto> {
return this.httpClient.patch(
`/users/${encodeURIComponent(request.userId)}`,
_.omit(request, "userId", "userVersion"),
{
params: _.pick(request, "userVersion"),
},
);
}
}
This repository is released under version 2.0 of the Apache License.
FAQs
axios for NestJS
The npm package @byndyusoft/nest-http-client receives a total of 59 weekly downloads. As such, @byndyusoft/nest-http-client popularity was classified as not popular.
We found that @byndyusoft/nest-http-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.