Skip to content

WebSocket API

Avvrik edited this page Dec 4, 2018 · 73 revisions

KeyChain contains a WebSocket API. This API can be used to stream information from a KeyChain instance to any client that implements WebSockets. Implementations in different languages:

  • NodeJS
  • Python
  • JavaScript/HTML
  • etc

Connect your WebSocket implementation to http://localhost:16384/.

Demo page in JavaScript

Here you will find the code of the demo page that connects to WebSocket. This page will be automatically installed together with the KeyChain.

On this demo page you can test the KeyChain commands.

Message format

Each WebSocket API message is a JSON serialized object containing a command with the corresponding parameters.

For full comprehensive descriptions of the commands, acceptable parameters and values, go to the Protocol.

WebSocket integration guide

NodeJS integration example

The following will show the usage of websocket connections. We make use of the wscat application available via npm:

$ npm install -g wscat

A simple call would take the form:

$ wscat -c ws://127.0.0.1:16384
> { "command": "list"}

Successful Calls

The API will return a properly JSON formated response carrying the same id as the request to distinguish subsequent calls.

{"result":  ..data..}

Errors

In case of an error, the resulting answer will carry an error attribute and a description in human-readable format:

{"error":"Error: keyfile could not found by keyname"}

JavaScript integration example

Before you proceed with the integration, you need to download and install KeyChain.

After installing KeyChain, connect to http://localhost:16384/. When the connection is established, you will see the KeyChain page.

You can find the code for the demo page and the page itself up in the Demo page in JavaScript section.

Clone this wiki locally