SDK
SDK Javascript v7.x
2

Constructor #

Use this constructor to create a new instance of the Http protocol with specific options.

Arguments #

Copied to clipboard!
Http(host, [options]);

Argument Type Description
host
string
Kuzzle server hostname or IP
options
object
Http connection options

options #

Http protocol connection options.

Property Type
(default)
Description
customRoutes
object

({})
Add custom routes
Available since 6.2.0
headers
object

({})
Default headers sent with each HTTP request
Available since 7.7.5
port
number

(7512)
Kuzzle server port
sslConnection
boolean

(false)
Use SSL to connect to Kuzzle server
Deprecated since 7.4.0
ssl
boolean

(false)
Use SSL to connect to Kuzzle server. Defaults to true for ports 443 and 7443.
timeout
number

(0)
Connection timeout in milliseconds (0 means no timeout)
Available since 6.2.1

Note:

customRoutes are used to define plugins API routes or to overwrite existing API routes.
They must have the following format:

Copied to clipboard!
{
  'my-plugin/my-controller': {
    action: { verb: 'GET', url: '/some/url' },
    action2: { verb: 'GET', url: '/some/url/with/:parameter' }
  }
}

Return #

A Http protocol instance.

Usage #

Copied to clipboard!
// Loads the Http protocol
const
  {
    Kuzzle,
    Http
  } = require('kuzzle-sdk');
const customRoutes = {
  'nyc-open-data-plugin/driver': {
    enroll: { verb: 'POST', url: '/_plugin/nyc-open-data-plugin/drivers' },
    remove: { verb: 'DELETE', url: '/_plugin/nyc-open-data-plugin/drivers/:driverId' }
  }
};
const headers = {
  'Accept-Encoding': 'gzip, deflate'
};
const options = {
  customRoutes,
  headers,
  sslConnection: false
};
// Instantiates the Http protocol
const httpProtocol = new Http('kuzzle', options);
// Use it with Kuzzle
const kuzzle = new Kuzzle(httpProtocol);