Skip to content
This repository has been archived by the owner. It is now read-only.
[Migrated to nestcloud repository]Feign is a nest http decorators library that makes writing nodejs http clients easier.
TypeScript JavaScript
Branch: master
Clone or download
Latest commit d899f02 Mar 25, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib suport brakes Mar 25, 2019
.eslintrc.js initial commit Jun 12, 2018
.gitignore initial commit Jun 12, 2018
.npmignore initial commit Jun 12, 2018
.prettierrc initial commit Jun 12, 2018 suport brakes Mar 25, 2019
index.d.ts initial commit Jun 12, 2018
index.js initial commit Jun 12, 2018
index.ts.js initial commit Jun 12, 2018
package.json suport brakes Mar 25, 2019
tsconfig.json migrate to nestcloud npm org Mar 5, 2019
tslint.json initial commit Jun 12, 2018
yarn.lock suport brakes Mar 25, 2019

Nest Logo


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/consul-loadbalance @nestcloud/consul consul

Quick Start

Import Module

import { Module } from '@nestjs/common';
import { FeignModule } from '@nestcloud/feign';
import { NEST_CONSUL_LOADBALANCE } from '@nestcloud/common';

  imports: [FeignModule.register({
    dependencies: [], // If use @nestcloud/consul-loadbalance module, please set NEST_CONSUL_LOADBALANCE
    axiosConfig: {},
export class ApplicationModule {}



import { Injectable } from "@nestjs/common";
import { Loadbalanced, Get, Query, Post, Body, Param, Put, Delete } from "@nestcloud/feign";
@Loadbalanced('user-service') // open lb support
export class UserClient {
    getUsers(@Query('role') role: string) {
    @Loadbalanced(false) // close lb support
    getRemoteUsers() {
    createUser(@Body('user') user: any) {
    updateUser(@Param('userId') userId: string, @Body('user') user: any) {
    deleteUser(@Param('userId') userId: string) {


export class UserService {
    constructor(private readonly userClient: UserClient) {}
    doCreateUser() {
        this.userClient.createUser({name: 'test'});


Get|Post|Put|Delete|Options|Head|Patch|Trace(uri: string, options?: AxiosRequestConfig): MethodDecorator

Route decorator.

field type description
uri string the url
options object axios config,see axios

Param|Body|Query|Header(field?: string): ParameterDecorator

Parameter decorator.

field type description
field string the field name

SetHeader|SetQuery|SetParam|SetBody(field: string, value: any): MethodDecorator

constant parameter decorator

field type description
field string the field name
value string | number | object the field value

Response(): MethodDecorator

If set this decorator, it will return full http response.

ResponseHeader(): MethodDecorator

If set this decorator, it will return response.headers.

ResponseBody(): MethodDecorator

It's a default decorator, it will return

ResponseType(type: string): MethodDecorator

set response data type, eg: 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream', default 'json'

ResponseEncode(type: string): MethodDecorator

Set response data encode, default 'utf8'

Loadbalanced(service: string | boolean): ClassDecorator | MethodDecorator

Open or close lb support.

Interceptor<T extends IInterceptor>(interceptor: { new(): T })

add interceptor,such as:


import { IInterceptor } from "@nestcloud/feign";
import { AxiosResponse, AxiosRequestConfig } from 'axios';

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, Interceptor } from "@nestcloud/feign";
import { AddHeaderInterceptor } from './AddHeaderInterceptor';

export class ArticleClient {
    getArticles() {

interceptor processing:

export class Client {

    getArticles() {


interceptor1 request
interceptor2 request
interceptor3 request
interceptor4 request
interceptor4 response
interceptor3 response
interceptor2 response
interceptor1 response

Brakes(config?: BrakesConfig | boolean): ClassDecorator | MethodDecorator

Open circuit supports.

Fallback(Fall: { new(): T })

Add Custom fallback, use together with Brakes decorator.

HealthChecker(Checker: { new(): T })

Add Health Checker for Brakes, use together with Brakes decorator, please set heathCheck: true, such as

@Brakes({healthCheck: true})

Stay in touch


NestCloud is MIT licensed.

You can’t perform that action at this time.