HTTP, WS & TCP
Hivekit supports connections via HTTP, WebSocket, and raw TCP (and we intend to add additional protocols such as MQTT soon). The preferred way to interact with Hivekit is via a client SDK - but if you wish to give the raw protocol a go, here's how:
HTTP
POST
an array of actions (see protocol structure) to https://api.hivekit.io/v1/http. Include your API token as an Authorization: Bearer YOUR_TOKEN
header. E.g. via curl
:
curl -X POST https://api.hivekit.io/v1/http \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-H 'Content-Type: application/json' \
-d '[{"typ":"obj","act":"lis","rea":"my-realm-id-123"}]'
or NodeJS
const needle = require('needle');
const options = {
json: true,
headers: {
'Authorization': `Bearer ${token}`
}
};
const data = [{"typ":"obj","act":"lis","rea":"realm-a-f7k1a0mpvko-4rnv5psdle8"}];
const response = await needle('post', 'https://api.hivekit.io/v1/http', data, options);
WebSocket
To establish a Websocket connection, connect to wss://api.hivekit.io/v1/ws
and send the string Bearer YOUR_TOKEN
before sending any other message. If your authentication was succesfull, you should receive a message like this:
[{
"typ":"sys", // type = system
"act":"aut", // action = authenticate
"res":"suc", // result = success
"dat":{
"version": "0.12.3", // server version
"buildDate": "30 Mar 2023 19:54:46" // server build date
}
}]
Once you received this message, you can start sending regular arrays of actions (see protocol structure). Here's a JavaScript example that uses the Websocket client built into browsers:
const ws = new WebSocket('wss://api.hivekit.io/v1/ws')
ws.on('open', () => {
ws.send('Bearer YOUR_API_TOKEN');
})
ws.on('message', msgBuffer => {
JSON.parse(msgBuffer.toString()).forEach(msg => {
if (msg.typ == 'sys' && msg.act == 'aut' && msg.res == 'suc') {
ws.send(JSON.stringify({"typ":"obj","act":"lis","rea":"realm-a-f7k1a0mpvko-4rnv5psdle8"}]));
// hurray, we're connected and authenticated. Time to start sending messages
}
})
})
TCP
You can also talk to Hivekit using a raw TCP socket. To do so, connect to 54.72.148.101:81
with a TCP client of your choice. From here on, it works the same as the Websocket connection described above (send Auth Message, wait for response, then start sending action arrays).