@tropos/kong-admin-api-client
v0.2.2
Published
Library to interact with the Kong Admin API.
Downloads
12
Readme
Kong Admin API Node.js Library
The Kong Admin API Node library provides convenient access to the Kong Admin API from applications written in server-side JavaScript.
Installation
Install the package with:
npm install @tropos/kong-admin-api-client --save
Usage
The package needs to be configured with your Admin API's URL.
const Kong = require('@tropos/kong-admin-api-client');
const adminAPIURL = 'http://localhost:8001';
// Create a new client with the default exported constructor
const kong = new Kong({ adminAPIURL });
The kong object has properties that correspond to all the Kong Admin API resources. The currently supported resources are:
- Services
- Routes
- Consumers
- Credentials
// use these objects to interface with the API
kong.services
kong.routes
kong.consumers
All of the resources have standard methods you can use to access the API:
- create
- get
- list
- update
- delete
// use the resource properties to interface with the API
// all the resources have the standard API methods
kong.services.get();
kong.routes.list();
kong.consumers.delete();
API
Services
#create
Creates a new service
Params
Example
await kong.services.create({
name: 'my_service',
url: 'https://jsonplaceholder.typicode.com/posts/1',
});
Returns
This method returns the direct response from the Kong Admin API server.
{
"id": "4e13f54a-bbf1-47a8-8777-255fed7116f2",
"created_at": 1488869076800,
"updated_at": 1488869076800,
"connect_timeout": 60000,
"protocol": "http",
"host": "example.org",
"port": 80,
"path": "/api",
"name": "example-service",
"retries": 5,
"read_timeout": 60000,
"write_timeout": 60000
}