kuzzle-sdk
Version:
Official Javascript SDK for Kuzzle
89 lines (88 loc) • 2.5 kB
TypeScript
import { HttpRoutes, JSONObject } from "../types";
import { RequestPayload } from "../types/RequestPayload";
import { KuzzleAbstractProtocol } from "./abstract/Base";
/**
* Http protocol used to connect to a Kuzzle server.
*
* The Http protocol cannot use the realtime capabilities of Kuzzle.
*/
export default class HttpProtocol extends KuzzleAbstractProtocol {
private _routes;
private _timeout;
private _customRoutes;
private _defaultHeaders;
/**
* @param host Kuzzle server hostname or IP
* @param options Http connection options
* - `customRoutes` Add custom routes
* - `headers` Default headers sent with each HTTP request (default: `{}`)
* - `port` Kuzzle server port (default: `7512`)
* - `ssl` Use SSL to connect to Kuzzle server. Default `false` unless port is 443 or 7443.
* - `timeout` Connection timeout in milliseconds (default: `0`)
*/
constructor(host: string, options?: {
port?: number;
/**
* @deprecated Use `ssl` instead
*/
sslConnection?: boolean;
ssl?: boolean;
customRoutes?: HttpRoutes;
timeout?: number;
headers?: JSONObject;
});
/**
* @deprecated Use `routes` instead
*/
get http(): HttpRoutes;
/**
* Returns a list of available routes
*/
get routes(): HttpRoutes;
/**
* `http` or `https`
*/
get protocol(): string;
/**
* Always returns `true`
*/
get connected(): true;
/**
* Connection timeout in milliseconds
*/
get timeout(): number;
set timeout(timeout: number);
/**
* Connect to the server
*/
connect(): Promise<void>;
/**
* Enable cookie authentication support at protocol level
*/
enableCookieSupport(): void;
/**
* Preprocess and format the request
*
* @param {Object} data
* @returns {Promise<any>}
*/
formatRequest(request: RequestPayload, options?: JSONObject): {
method: any;
path: string;
payload: any;
};
/**
* Sends a payload to the connected server
*
* @param {Object} data
* @returns {Promise<any>}
*/
send(request: RequestPayload, options?: JSONObject): void;
_sendHttpRequest({ method, path, payload, }: {
method: string;
path: string;
payload: JSONObject;
}): any;
_constructRoutes(publicApi: any): {};
_warn(message: any): void;
}