SDK
SDK Javascript v7.x
2

Http #

The Http protocol can be used by an instance of the SDK to communicate with your Kuzzle server.

This protocol does not allow to use the real-time notifications.

If you need real-time features, then you have to use the WebSocket protocol.

About HTTP routing #

Available since 6.2.0

This protocol needs to build routes from the name of the controller and the action used. These routes are made available by Kuzzle via the server:publicApi method or the server:info method.

Available since Kuzzle 1.9.0

For confidentiality reasons, it is preferable to expose only the server:publicApi route to the anonymous user.
If this route is not available, the SDK will use the static definition of API routes that does not include routes developed in plugins.

Finally, it is also possible to manually define the routes to the actions of its plugins using the customRoutes option with the Http protocol constructor.

Properties #

Property nameTypeDescriptionGet/Set
connected
boolean
Always returns trueGet
host
string
Kuzzle server hostGet
http
object
Returns a list of available routes
Deprecated since 6.2.0
Get
routes
object
Returns a list of available routes
Available since 6.2.0
Get
port
number
Kuzzle server portGet
protocol
string
https or httpGet
ssl
boolean
true if ssl is activeGet
timeout
number
Connection timeout in milliseconds
Available since 6.2.1
Get/Set

Note:

A timeout of 0 means that the connection will never timeout.

Constructor #

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

Arguments #

Http(host, [options]);

ArgumentTypeDescription
host
string
Kuzzle server hostname or IP
options
object
Http connection options

options #

Http protocol connection options.

PropertyType
(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:

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

Return #

A Http protocol instance.

Usage #

// 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);