
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@nestcloud/feign
Advanced tools
Feign is a nest http decorators library that makes writing nodejs http clients easier.
A component of nestcloud. NestCloud is a nest framework micro-service solution.
This is a Nest module for writing nestjs http clients easier.
$ npm i --save @nestcloud/feign @nestcloud/loadbalance @nestcloud/consul consul
import { Module } from '@nestjs/common';
import { ConsulModule } from '@nestcloud/consul';
import { ServiceModule } from '@nestcloud/service';
import { LoadbalanceModule } from '@nestcloud/loadbalance';
import { BootModule } from '@nestcloud/boot';
import { FeignModule } from '@nestcloud/feign';
import { NEST_BOOT, NEST_LOADBALANCE, NEST_CONSUL } from '@nestcloud/common';
@Module({
imports: [
BootModule.register(__dirname, 'bootstrap.yml'),
ConsulModule.register({dependencies: [NEST_BOOT, NEST_CONSUL]}),
ServiceModule.register({ dependencies: [NEST_BOOT, NEST_CONSUL] }),
LoadbalanceModule.register({ dependencies: [NEST_BOOT] }),
FeignModule.register({ dependencies: [NEST_BOOT, NEST_LOADBALANCE] }), // or NEST_CONSUL_CONFIG
],
})
export class ApplicationModule {}
feign:
axios:
timeout: 1000
import { Injectable } from "@nestjs/common";
import { Get, Query, Post, Body, Param, Put, Delete } from "@nestcloud/feign";
@Injectable()
export class UserClient {
@Get('/users')
getUsers(@Query('role') role: string) {
}
@Get('http://test.com/users')
getRemoteUsers() {
}
@Post('/users')
createUser(@Body('user') user: any) {
}
@Put('/users/:userId')
updateUser(@Param('userId') userId: string, @Body('user') user: any) {
}
@Delete('/users/:userId')
deleteUser(@Param('userId') userId: string) {
}
}
import { Injectable } from "@nestjs/common";
import { Loadbalanced, Get, Query } from "@nestcloud/feign";
@Injectable()
@Loadbalanced('user-service') // open loadbalance supports, need @nestcloud/loadbalance module.
export class UserClient {
@Get('/users')
getUsers(@Query('role') role: string) {
}
@Get('http://test.com/users')
@Loadbalanced(false) // close loadbalance supports.
getRemoteUsers() {
}
}
import { IFallback } from "@nestcloud/feign";
import { Injectable, ServiceUnavailableException } from "@nestjs/common";
import { AxiosResponse } from "axios";
@Injectable()
export class CustomFallback implements IFallback {
fallback(): Promise<AxiosResponse | void> | AxiosResponse | void {
throw new ServiceUnavailableException('The service is unavailable, please retry soon.');
}
}
import { IHealthCheck } from "@nestcloud/feign";
import { Injectable } from "@nestjs/common";
import { HealthClient } from "./health.client";
@Injectable()
export class CustomCheck implements IHealthCheck {
constructor(
private readonly client: HealthClient
) {
}
async check(): Promise<void> {
await this.client.checkHealth();
}
}
import { Injectable } from "@nestjs/common";
import { UseBrakes, UseFallback, UseHealthCheck, Get, Query } from "@nestcloud/feign";
import { CustomFallback } from "./custom.fallback";
import { CustomCheck } from "./custom.check";
@Injectable()
@UseBrakes({
statInterval: 2500,
threshold: 0.5,
circuitDuration: 15000,
timeout: 250,
healthCheck: true,
})
@UseFallback(CustomFallback)
@UseHealthCheck(CustomCheck)
export class UserClient {
}
import { Injectable } from '@nestjs/common';
import { IInterceptor } from "@nestcloud/feign";
import { AxiosResponse, AxiosRequestConfig } from 'axios';
@Injectable()
export class AddHeaderInterceptor implements IInterceptor {
onRequest(request: AxiosRequestConfig): AxiosRequestConfig {
request.headers['x-service'] = 'service-name';
return request;
}
onResponse(response: AxiosResponse): AxiosResponse {
return response;
}
onRequestError(error: any): any {
return Promise.reject(error);
}
onResponseError(error: any): any {
return Promise.reject(error);
}
}
import { Injectable } from "@nestjs/common";
import { Get, UseInterceptor } from "@nestcloud/feign";
import { AddHeaderInterceptor } from "./middlewares/AddHeaderInterceptor";
@Injectable()
@UseInterceptor(AddHeaderInterceptor)
export class ArticleClient {
@Get('https://api.apiopen.top/recommendPoetry')
getArticles() {
}
}
examples:
@UseInterceptor(Interceptor1)
@UseInterceptor(Interceptor2)
export class Client {
@UseInterceptor(Interceptor3)
@UseInterceptor(Interceptor4)
getArticles() {
}
}
result:
interceptor1 request
interceptor2 request
interceptor3 request
interceptor4 request
interceptor4 response
interceptor3 response
interceptor2 response
interceptor1 response
Route decorator.
| field | type | description |
|---|---|---|
| uri | string | the url |
| options | object | axios config,see axios |
Parameter decorator.
| field | type | description |
|---|---|---|
| field | string | the field name |
constant parameter decorator
| field | type | description |
|---|---|---|
| field | string | the field name |
| value | string | number | object | the field value |
If set this decorator, it will return full http response.
If set this decorator, it will return response.headers.
It's a default decorator, it will return response.data.
set response data type, eg: 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream', default 'json'
Set response data encode, default 'utf8'
Open or close lb support.
Use interceptor, supports dynamic import and inject.
Open circuit supports.
Add Custom fallback, use together with Brakes decorator, supports dynamic import and inject.
Add Health Checker for Brakes, use together with Brakes decorator, supports dynamic import and inject.
If you use health check, please set heathCheck: true, such as
@Brakes({healthCheck: true})
NestCloud is MIT licensed.
FAQs
Feign is a nest http decorators library that makes writing nodejs http clients easier.
The npm package @nestcloud/feign receives a total of 225 weekly downloads. As such, @nestcloud/feign popularity was classified as not popular.
We found that @nestcloud/feign demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.