Module: kingkong

Primay Client class for interfacing with kong


new (require("kingkong"))( [options])

Extends:
  • EventEmitter
Parameters:
Name Type Argument Description
options Object <optional>
Properties
Name Type Argument Default Description
hosts String | Array.<String> <optional>
http://localhost:8001
apis module:kingkong~Api | Array.<module:kingkong~Api> <optional>

an array of api configurations to be created or updated when the instance is created

autodelete Boolean <optional>
false

if set to true api plugins will be deleted from kong when they are not present in the related config

Examples
var king = (new require('kingkong')({
   hosts:['http://localhost:8001', 'http://localhost:8002', 'http://locahost:8003']
});
var king = (new require('kingkong')({
      hosts:'http://localhost:8001, http://localhost:8002, http://locahost:8003',
      apis:[{
          "upstream_url": "http://192.168.1.135:3000/api/v1",
          uris: ["/integration"],
          "strip_uri": true,
          "name": "integration",
          "plugins":{
            "http-log":{
              config:{
                  http_endpoint:'http://192.168.1.135:3005',
                  method:'POST'
              }
            }
          }
      }]
   });

Requires

Methods


create(resource, items)

Creates one or more instance of a resource. If the resource already exists, it will be updated

Parameters:
Name Type Description
resource String

The type of resource to generate a url for ( api, plugin, consumer )

items Object | Array.<Object>

configurations of the resource to create

Returns:
Type
TYPE

destroy(resource, id)

Destroys a specific resource

Parameters:
Name Type Description
resource String

the type of resource to operate on ( api, consumer, plugin )

id String

The id or name of a specific resource to destroy

Returns:
Type
Promise

get(resource, id)

List a specific resource

Parameters:
Name Type Description
resource String

the resource to get

id String

or name of the specific instance to get

Returns:
Type
Array

list(resource)

List a specific resource type

Parameters:
Name Type Description
resource String

the resource to list

Returns:

Resolves an array of resource objects

Type
Promise

plugins(id, data)

Creates and configures plugins for a specific API instance

Parameters:
Name Type Description
id String

of the api the plugin should be assiociated with

data Object

The configuration for the plugin

Returns:
Type
Promise

request(resource [, id] [, data] [, codes])

Generates a valid url for a kong request, cycling through one of the hosts for each call

Parameters:
Name Type Argument Description
resource String

The type of resource to generate a url for ( api, plugin, consumer )

id String <optional>

the id or name of a specific resource

data Object <optional>

optional body of the request

codes Array <optional>

optional array of HTTP status codes that are not considered an error

Returns:

A promise that will resolve to the result of the request

Type
Promise

sync()

Syncs api and consumer configuration with a kong instance.
matching records will be updated
missing records will be created
records that do not exists in the configuration will be removed

Fires:
Returns:
Type
Promise

update(resource, id, data)

pudates a resource in place by id, or name

Parameters:
Name Type Description
resource String

the name of the resource type ( api, plugin, consumer)

id String

The id or name of the resource to update

data Object

a data object to update the resource with

Returns:
Type
Object

url(resource [, id])

Generates a valid url for a kong request, cycling through one of the hosts for each call

Parameters:
Name Type Argument Description
resource String

The type of resource to generate a url for ( api, plugin, consumer )

id String <optional>

the id or name of a specific resource

Returns:

the url for request to kong

Type
String

Type Definitions


Api

Configuration for creating an api instance with kong

Type:
  • Object
Properties:
Name Type Argument Default Description
plugins Object <optional>

An object where the key is the name of a valid plugin, and the value is an object of the configuration to create/update it with

name String

The name of the being created / updated

request_host String <optional>

Public DNS, or ip address

request_path String <optional>

The public path that points to your api - /somservice. On of request_host or request_path must be specified

strip_request_path Boolean <optional>
false

Determines if the original request path is removed before proxying the request to the upstream service

preserve_host Boolean <optional>
false

Determines if the original Host header sent from the client should be preserved. If false, upstream_url is used

upstream_url String

The target URL of the backend service responsible for handling the request - http://api.foobar.com

Events


sync