|
| 1 | +# Websocket Api |
| 2 | + |
| 3 | +The websocket api is the interface for any frontend to communicate with the backend. |
| 4 | +<br> |
| 5 | +By default the websocket is available at `/ws`. (e.g. `wss://server.cryptic-game.net/ws`) |
| 6 | + |
| 7 | +## Request |
| 8 | + |
| 9 | +```json |
| 10 | +{ |
| 11 | + "tag": "random string", |
| 12 | + "endpoint": "user/register", |
| 13 | + "data": { |
| 14 | + "username": "TestUser", |
| 15 | + "password": "#Test123" |
| 16 | + } |
| 17 | +} |
| 18 | +``` |
| 19 | + |
| 20 | +| Name | Description | |
| 21 | +|------------|----------------------------------------------------------------------------------------------------------------| |
| 22 | +| `tag` | The tag is a random string witch is copied to the response of this request to identify the according response. | |
| 23 | +| `endpoint` | The endpoint witch should be executed. | |
| 24 | +| `data` | The data witch should be passed to the endpoint. | |
| 25 | + |
| 26 | +## Response |
| 27 | + |
| 28 | +```json |
| 29 | +{ |
| 30 | + "status": { |
| 31 | + "code": 200, |
| 32 | + "name": "OK" |
| 33 | + }, |
| 34 | + "error": "<message>", // optional |
| 35 | + "tag": "random string", |
| 36 | + "data": { |
| 37 | + "id": "fd973bf5-3801-402f-8c85-d5313aa02baa", |
| 38 | + "user_id": "2cea82a0-3425-4d0e-8e1b-4823ad744162" |
| 39 | + } |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +| Name | Description | |
| 44 | +|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 45 | +| `status` | The status code and name of the response. The codes are similar to the [Http Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status). | |
| 46 | +| `error` | A optional error message. | |
| 47 | +| `tag` | The same value as in the request. | |
| 48 | +| `data` | A optional data witch the endpoint produced. | |
| 49 | + |
| 50 | +## Notification |
| 51 | + |
| 52 | +```json |
| 53 | +{ |
| 54 | + "status": { |
| 55 | + "code": 900, |
| 56 | + "name": "Notification" |
| 57 | + }, |
| 58 | + "topic": "MESSAGE_SEND", |
| 59 | + "data": { |
| 60 | + "user_id": "fd973bf5-3801-402f-8c85-d5313aa02baa", |
| 61 | + "whisper": false, |
| 62 | + "content": "Hello" |
| 63 | + } |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +| Name | Description | |
| 68 | +|----------|--------------------------------------------------------------------| |
| 69 | +| `status` | The status is in every Notification the same. | |
| 70 | +| `topic` | The topic of the notification. It can be interpreted as a channel. | |
| 71 | +| `data` | A optional data of the notification. | |
0 commit comments