YAWE allows you to listen to changes on your endpoints using websockets.
To do this, you use the same endpoint created under projects, using the protocol wss instead of https.
Usage with websockets:
When opening a connection to a websocket, the parameters of the URL are validated like we do for HTTP requests, such as, endpoint name, key, origin, data access and authentication. If any of the checks fail, the connection fails and an error is sent to the user.
If the endpoint is secure, your user needs to be logged in first. As the cookie with the access token is HTTP-only, it is sent automatically with the request.
|yawe_access_token||The Access token is required for secure endpoints.|
It is set when login in and is automatically sent in the websocket request.
For more information check Secure Endpoints.
The following table describes the Request parameters to open a connection. Parameters not listed below are ignored.
URL example: wss://app.yawe.dev/api/1/ce/examples/unsecure-endpoint?key=d59eb2859c284168ac48aef65046d5dd
wss:// - Secure websocket over HTTPS.
|baseUrl||Base url for calling the API.|
Value: The current value is 1.
|customEndpointRoute||The route which identifies custom endpoints.|
Default value: ce
|userEndpoint||The endpoint name generated by the user.|
Value: the name created at https://app.yawe.dev
|apiKey||The API Key of the project.||Yes|
The connection to the websocket can fail or be terminated due to one of the reasons listed in the table below. You will be able to read the error message in the
reason property of the error message.
If the connection is successful, when there's new data in the endpoint or an update you will receive the affect record in the websocket message. Below is an example of such message:
Note: For files, if there are multiple uploads you will receive an array of records in the message.