> For the complete documentation index, see [llms.txt](https://docs.nestjstools.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nestjstools.com/apisix-client/getting-started/usage-example.md).

# Usage 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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nestjstools.com/apisix-client/getting-started/usage-example.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
