Primay Client class for interfacing with kong
new (require("kingkong"))( [options])
Extends:
- EventEmitter
Parameters:
| Name | Type | Argument | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Properties
|
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
- module:prime
- module:url
- module:util
- module:debug
- module:co
- module:co-request
- module:urljoin
- module:events
- module:mout/lang/toArray
- module:mout/lang/isString
- module:mout/lang/compact
- module:mout/collection/forEach
- module:kingkong/lib/options
- module:kingkong/lib/validation/api
- module:kingkong/lib/validation/consumer
- module:kingkong/lib/validation/plugin
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 resourceString The type of resource to generate a url for ( api, plugin, consumer )
itemsObject | Array.<Object> configurations of the resource to create
Returns:
- Type
- TYPE
-
destroy(resource, id)
-
Destroys a specific resource
Parameters:
Name Type Description resourceString the type of resource to operate on ( api, consumer, plugin )
idString The id or name of a specific resource to destroy
Returns:
- Type
- Promise
-
get(resource, id)
-
List a specific resource
Parameters:
Name Type Description resourceString the resource to get
idString or name of the specific instance to get
Returns:
- Type
- Array
-
list(resource)
-
List a specific resource type
Parameters:
Name Type Description resourceString 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 idString of the api the plugin should be assiociated with
dataObject 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 resourceString The type of resource to generate a url for ( api, plugin, consumer )
idString <optional>
the id or name of a specific resource
dataObject <optional>
optional body of the request
codesArray <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 removedFires:
Returns:
- Type
- Promise
-
update(resource, id, data)
-
pudates a resource in place by id, or name
Parameters:
Name Type Description resourceString the name of the resource type ( api, plugin, consumer)
idString The id or name of the resource to update
dataObject 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 resourceString The type of resource to generate a url for ( api, plugin, consumer )
idString <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 pluginsObject <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
nameString The name of the being created / updated
request_hostString <optional>
Public DNS, or ip address
request_pathString <optional>
The public path that points to your api -
/somservice. On ofrequest_hostorrequest_pathmust be specifiedstrip_request_pathBoolean <optional>
false Determines if the original request path is removed before proxying the request to the upstream service
preserve_hostBoolean <optional>
false Determines if the original
Hostheader sent from the client should be preserved. If false,upstream_urlis usedupstream_urlString The target URL of the backend service responsible for handling the request -
http://api.foobar.com
Events
-
sync
-