REST requests will use the req function we made in the JSON:API examples

Connection example

const token = "token_from_authentication";

req("/websocket/token", token, "GET").then((response) => {
  if (response.data)
  {
    const connection = new WebSocket("wss://api.maskon.no/websocket?token=" + response.data.attributes.token);
    connection.addEventListener("message", (event) => {
        console.log("Message from server ", event.data);
    });
  }
});

Responses

The different types of responses are

Command

A valid command response will allways contain the response property

{
  "cmd": "subscribe",
  "response": "value"
}