If you find Kong Admin helpful, you can show your support and help me continue maintaining the project by buying me a coffee.
This library is on development stage, so be careful when using it on production environment.
The current version from May 2019 covers all methods listed on https://docs.konghq.com/1.1.x/admin-api/.
npm install node-kong-admin --save
const KongLib = require('node-kong-admin');
const KongClient = new KongLib({ url: 'http://kong.docker:8001' });
let createData = {
name: 'FirstService',
host: 'localhost'
};
KongClient.service.create(createData, function(err, done) {
if(err) throw new Error(err);
console.log('Created: ', done);
// Do whatever you have todo here
});
We are currently covering the following modules:
| Method | Example | Doc |
|---|---|---|
| info | KongClient.node.info(callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-node-information |
| status | KongClient.node.status(callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-node-status |
| Method | Example | Doc |
|---|---|---|
| dbless | KongClient.config.dbless(filePath, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-db-less-config |
| Method | Example | Doc |
|---|---|---|
| list | KongClient.tag.list(offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-all-tags |
| listByTag | KongClient.tag.listByTags(tags, offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-entity-ids-by-tag |
| Method | Example | Doc |
|---|---|---|
| create | KongClient.service.create(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-service |
| update | KongClient.service.update(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-service |
| updateByRoute | KongClient.service.updateByRoute(routeNameOrId, data, callback); |
|
| updateByPlugin | KongClient.service.updateByPlugin(pluginId, data, callback); |
|
| updateOrCreate | KongClient.service.updateOrCreate(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-or-create-service |
| updateOrCreateByRoute | KongClient.service.updateOrCreateByRoute(routeNameOrId, data, callback); |
|
| updateOrCreateByPlugin | KongClient.service.updateOrCreateByPlugin(pluginId, data, callback); |
|
| get | KongClient.service.get(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-service |
| list | KongClient.service.list(offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-services |
| delete | KongClient.service.delete(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#delete-service |
| deleteByRoute | KongClient.service.deleteByRoute(routeNameOrId, callback); |
| Method | Example | Doc |
|---|---|---|
| create | KongClient.route.create(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-route |
| createByService | KongClient.route.createByService(serviceNameOrId, data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-route |
| update | KongClient.route.update(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-route |
| updateByPlugin | KongClient.route.updateByPlugin(pluginId, data, callback); |
|
| updateOrCreate | KongClient.route.updateOrCreate(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-or-create-route |
| updateOrCreateByPlugin | KongClient.route.updateOrCreateByPlugin(pluginId, data, callback); |
|
| get | KongClient.route.get(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-route |
| getByPlugin | KongClient.route.getByPlugin(pluginId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-route |
| list | KongClient.route.list(offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-routes |
| listByService | KongClient.route.listByService(serviceNameOrId, offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-routes |
| delete | KongClient.route.delete(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#delete-route |
| Method | Example | Doc |
|---|---|---|
| create | KongClient.consumer.create(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-consumer |
| update | KongClient.consumer.update(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-consumer |
| updateByPlugin | KongClient.consumer.updateByPlugin(pluginId, data, callback); |
|
| updateOrCreate | KongClient.consumer.updateOrCreate(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-or-create-consumer |
| updateOrCreateByPlugin | KongClient.consumer.updateOrCreateByPlugin(pluginId, data, callback); |
|
| get | KongClient.consumer.get(usernameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-consumer |
| getByPlugin | KongClient.consumer.getByPlugin(pluginId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-consumer |
| list | KongClient.consumer.list(offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-consumers |
| delete | KongClient.consumer.delete(usernameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#delete-consumer |
| Method | Example | Doc |
|---|---|---|
| create | KongClient.plugin.create(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-plugin |
| createByRoute | KongClient.plugin.createByRoute(routeId, data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-plugin |
| createByService | KongClient.plugin.createByService(sericeId, data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-plugin |
| createConsumer | KongClient.plugin.createByConsumer(consumerId, data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-plugin |
| update | KongClient.plugin.update(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-plugin |
| updateOrCreate | KongClient.plugin.updateOrCreate(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-or-create-plugin |
| get | KongClient.plugin.get(pluginId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-plugin |
| list | KongClient.plugin.list(offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-plugins |
| listByRoute | KongClient.plugin.listByRoute(routeId, offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-plugins |
| listByService | KongClient.plugin.listByService(serviceId, offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-plugins |
| listByConsumer | KongClient.plugin.listByConsumer(consumerId, offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-plugins |
| delete | KongClient.plugin.delete(pluginId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#delete-plugin |
| Method | Example | Doc |
|---|---|---|
| create | KongClient.certificate.create(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-certificate |
| update | KongClient.certificate.update(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-certificate |
| updateOrCreate | KongClient.certificate.updateOrCreate(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-or-create-certificate |
| get | KongClient.certificate.get(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-certificate |
| list | KongClient.certificate.list(offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-certificates |
| delete | KongClient.certificate.delete(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#delete-certificate |
| Method | Example | Doc |
|---|---|---|
| create | KongClient.sni.create(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-sni |
| createByCertificate | KongClient.sni.createByCertificate(certificateNameOrId, data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-sni |
| update | KongClient.sni.update(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-sni |
| updateOrCreate | KongClient.sni.updateOrCreate(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-or-create-sni |
| get | KongClient.sni.get(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-sni |
| list | KongClient.sni.list(offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-snis |
| listByCertificate | KongClient.sni.listByCertificate(certificateNameOrId, offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-snis |
| delete | KongClient.sni.delete(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#delete-sni |
| Method | Example | Doc |
|---|---|---|
| create | KongClient.upstream.create(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-upstream |
| update | KongClient.upstream.update(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-upstream |
| updateByTarget | KongClient.upstream.updateByTarget(targetHostAndPortOrId, data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-upstream |
| updateOrCreate | KongClient.upstream.updateOrCreate(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-or-create-upstream |
| updateOrCreateByTarget | KongClient.upstream.updateOrCreateByTarget(targetHostAndPortOrId, data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#update-or-create-upstream |
| get | KongClient.upstream.get(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-upstream |
| getByTarget | KongClient.upstream.getByTarget(targetHostAndPortOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-upstream |
| list | KongClient.upstream.list(offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-upstreams |
| delete | KongClient.upstream.delete(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#delete-upstream |
| deleteByTarget | KongClient.upstream.deleteByTarget(targetHostAndPortOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#delete-upstream |
| health | KongClient.upstream.health(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#show-upstream-health-for-node |
| Method | Example | Doc |
|---|---|---|
| create | KongClient.target.create(data, callback); |
https://docs.konghq.com/1.1.x/admin-api/#add-target |
| get | KongClient.target.get(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#retrieve-target |
| list | KongClient.target.list(upstreamHostAndPortOrId, offset, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-targets |
| listAll | KongClient.target.listAll(upstreamNameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#list-all-targets |
| delete | KongClient.target.delete(nameOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#delete-target |
| setHealthy | KongClient.target.setHealthy(upstreamNameOrId, targetHostAndPortOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#set-target-as-healthy |
| setUnhealthy | KongClient.target.setHealthy(upstreamNameOrId, targetHostAndPortOrId, callback); |
https://docs.konghq.com/1.1.x/admin-api/#set-target-as-unhealthy |
