hands-clappingUsage example

Inject the Client

import { Injectable, OnModuleInit } from '@nestjs/common';
import { ApisixClient, ApisixRouteRequest } from '@nestjstools/apisix-client';

@Injectable()
export class GatewaySyncService implements OnModuleInit {
  constructor(private readonly apisix: ApisixClient) {}

  async onModuleInit() {
    await this.ensureUserRoute();
  }

  private async ensureUserRoute() {
    const routeId = 'users-route';

    const desiredRoute: ApisixRouteRequest = {
      id: routeId,
      uri: '/users',
      methods: ['GET', 'POST'],
      upstream: {
        type: 'roundrobin',
        nodes: {
          'host.docker.internal:3000': 1,
        },
      },
    };

    await this.apisix.route().upsertRoute(routeId, desiredRoute);

    console.log('APISIX route updated');
  }
}

🔧 Configuration

Property
Description
Default

url

Base APISIX host

required

adminSecret

APISIX Admin API key

required

port

Admin API port

9180

prefix

Admin API prefix

apisix

global

Register module globally

true


🛠 Supported Gateway Resources

The client supports management of:

  • Routes

  • Services

  • Upstreams

  • Consumers

  • Plugins

Including commonly used plugin categories:

  • Authentication (JWT, key-auth, etc.)

  • Rate limiting

  • Traffic control

  • Transformation

  • Security

  • CORS

  • Request validation

Last updated

Was this helpful?