SymetryML Documentation

WebSocket API

WebSocket Overview

SymetryML supports the use of WebSocket technology on a subset of its API. This API can be used when lower latency is needed. Each WebSocket call contains a set of 3 pieces of information:

  • The header length
  • The headers, which are used to authenticate the request.
  • The message payload.

The message are string formatted using the following protocol

  • <Header-length>,<header><payload> ex:
  • 93,{headers=['some date','some md5','some authorization','some customer id','7.0'],extraKeys={}}{PAYLOAD}

The following table describes this information.

Header LengthLength of the header section.
Header

A JSON string containing 2 pieces of information - headers = an array of 5 strings used for authorization, in this order:

- date

- md5

- authorization hash code

- customer id

- protocol version, for example 7.0 (required since 7.0; the major version must be 7, as for the REST sym-version header). A message with only 4 header strings or another major version is refused with 400.

- extraKeys = contains extra information that depends on the WebSocket endpoint invoked. This Header field is mandatory on the first WebSocket message only.

WebSocket PayloadA JSON string representing a dataframe. See the DataFrame for more details

About WebSocket Authorization

With WebSocket, the following string must be used to create the Authorization hash code.

ItemDescription
AuthorizationSignature
SignatureBase64( HMAC-SHA256( Base64Decode(SecretKey), UTF-8-Encoding-Of( StringToSign ) ) )
StringToSignContent-MD5 + "\n" + Sym-Date + "\n" + SymetryML-customer-Id + "\n" + RequestBody + "\n" + ServicePath + "\n" + extraKeys (each extra key followed by "\n"). Since 7.0 the secret key is not part of the string; it is only the HMAC key.
Sym-Date formatSee the section Symetry Date Header
ServicePathPath of the URL to be invoked (for instance /symetry/ws/predict).
extraKeysEach extra key should be included individually on a separate new line. See example below for details.

Example of WebSocket String to Sign

H47KwjgTU5G7v8BJS+ttgg== + '\n'
2014-10-24 17:24:04 + '\n'
c1 + '\n'
{"attributeNames":["sepal_length","sepal_width","petal_length"],"data":[["4.3","3","1.1"]],"attributeTypes":["C","C","C"]} + '\n'
/symetry/ws/predict + '\n'
irisTest + '\n'
testLDA + '\n'

Learning Using WebSocket

This API function call allows users to learn a dataframe using WebSocket services.

URL

ws://SERVER_HOST/symetry/ws/learn

Extra Parameter

IndexShort DescriptionDescription
0SymetryML Project IDThe name of the project to learn the data.

WS Response

HTTP Status CodeHTTP Status MessageDescription
200OKSuccess.

Sample WS Request

Request URL:
ws://charm:8080/symetry/ws/learn
Request Message:
134,{"headers":["2014-10-24 14:28:03","PuAtwbvTrwlX8JQHWvtv7Q\u003d\u003d","<HMAC-SHA256 signature>","c1","7.0"],"extraKeys":["irisTest"]}{"attributeNames":["sepal_length","sepal_width","petal_length","petal_width","sepal_lengt_b1","sepal_lengt_b2","sepal_width_b1","sepal_width_b2","petal_length_b1","petal_length_b2","petal_width_b1","petal_width_b2","Iris_setosa","Iris_versicolor","Iris_virginica"],"data":[["4.3","3","1.1","0.1","1","0","0","1","1","0","1","0","1","0","0"],["4.8","3","1.4","0.1","1","0","0","1","1","0","1","0","1","0","0"],["4.9","3.1","1.5","0.1","1","0","0","1","1","0","1","0","1","0","0"],["4.9","3.
(...)
5","0","1","0","1","0","1","0","1","0","0","1"],["7.2","3.6","6.1","2.5","0","1","0","1","0","1","0","1","0","0","1"]],"attributeTypes":["C","C","C","C","B","B","B","B","B","B","B","B","B","B","B"]}

Forgetting Using WebSocket

This API function call allows users to forget a DataFrame of data using WebSocket services.

URL

ws://SERVER_HOST/symetry/ws/forget

Extra Parameter

IndexShort DescriptionDescription
0SymetryML Project IDThe name of the project to learn the data.

WS Response

HTTP Status CodeHTTP Status MessageDescription
200OKSuccess.

Predicting Using WebSocket

This API function call allows users to predict using WebSocket services.

URL

ws://SERVER_HOST/symetry/ws/predict

Extra Parameter

IndexShort DescriptionDescription
0SymetryML Project IDThe name of the project to learn the data.
1Model IdThe model name to use to make predictions.

WS Response

On success this WebSocket call will return a JSONResponseClient containing a KSVSMap entity. The format of this response is the same as with the SymetryML REST prediction API described in Prediction API.

Sample WS Request

Request URL
ws://charm:8080/symetry/ws/predict

Request Message:
144,{"headers":["2014-10-24 17:17:58","H47KwjgTU5G7v8BJS+ttgg\u003d\u003d","<HMAC-SHA256 signature>","c1","7.0"],"extraKeys":["irisTest","testLDA"]}{"attributeNames":["sepal_length","sepal_width","petal_length"],"data":[["4.3","3","1.1"]],"attributeTypes":["C","C","C"]}

Response:
{"statusCode":"OK","statusString":"OK","values":{"KSVSMap":{"values":[{"res":"1","normZ":"0.2929126883636288","resZ":"-0.4559922893809558","z0":"-3.840891864408894","z1LTz0":"false"}]}}}

On this page