---
url: https://gudhub.com/docs/rest-api/web-sockets/
title: "Web Sockets\n                #"
description: "Request of the current type are aimed to sending messages to users.They perform similar actions sending any messages, but are used in different cases. They also"
lang: uk
updated: 2026-09-11T09:10:42.901Z
---

# Web Sockets [#](https://gudhub.com/docs/rest-api/web-sockets/#web-sockets)

Request of the current type are aimed to sending messages to users.They perform similar actions - sending any messages, but are used in different cases. They also have a specific feature. After using these requests, in addition to the response, there will also be web socket messages.

There are two such requests:

1.  [ws/emit-to-user](#ws-emit-to-user)
2.  [ws/broadcast-to-app-subscribers](#ws-broadcast-to-app-subscribers)

## ws/emit-to-user [#](https://gudhub.com/docs/rest-api/web-sockets/#ws-emit-to-user)

The first request allows you to send various messages to a **specific person**, or rather, a user.

### Request [#](https://gudhub.com/docs/rest-api/web-sockets/#request)

| Request Method | Content Type | Request URL |
| :-- | :-- | :-- |
| `POST` | `Form Data` | `https://gudhub.com/GudHub/ws/emit-to-user` |

It consist of the data object that contains the message, an access token and the user ID.

| Property | Type | Description |
| :-- | :-- | :-- |
| data | `object` | _any data that is transmitted_ |
| token | `string` | _sender's token for access to the service_ |
| user\_id | `number` | _accepts ID of the recipient_ |

_**Example:**_

Copy

```json
data: {some_data: ‘here’,…}
token: "xDDdP3FhfYamgo8XEqdrtgfhyjq4hg2A443zTL6fyRNvGSvuQoxXGCS"
user_id: 22
```

> **`service_id`**: to receive this message on the client through [`gudhub.pipeService`](https://gudhub.com/docs/core-api/pipe-server/#websocket-bridge-wsemit-to-user), `data` must include a `service_id` field identifying the service/feature (e.g. `"gudhub_messenger"`). It is forwarded as-is in `response` and used as the pipe event name.

### Response [#](https://gudhub.com/docs/rest-api/web-sockets/#response)

In response, we receive all the data that was passed in the request, the API, and the sender's default application ID, which is created when the user has just registered.

Copy

```json
api: "/ws/emit-to-user"
app_id: 178
response: {some_data: ‘here’,…}
token: "xDDdP3FhfYamgo8XEqdrtgfhyjq4hg2A443zTL6fyRNvGSvuQoxXGCS"
user_id: 22
```

### WebSocket Message [#](https://gudhub.com/docs/rest-api/web-sockets/#websocket-message)

The **recipient user** will receive the following WebSocket message. It is very similar to the request response, but the **`user_id` is an ID of the message sender**.

Copy

```json
api: "/ws/emit-to-user"
app_id: 178
response: {some_data: ‘here’, service_id: "gudhub_messenger", …}
token: "xDDdP3FhfYamgo8XEqdrtgfhyjq4hg2A443zTL6fyRNvGSvuQoxXGCS"
user_id: 1
```

On the client, [`WebsocketHandler`](https://gudhub.com/docs/core-api/pipe-server/#websocket-bridge-wsemit-to-user) re-emits `response` through `gudhub.pipeService` using `response.service_id` as the event name and `{ user_id }` (the sender's ID, from this message's `user_id`) as the address.

### Status Code [#](https://gudhub.com/docs/rest-api/web-sockets/#status-code)

| Name | Description |
| :-- | :-- |
| 200 | user received a message |

## ws/broadcast-to-app-subscribers [#](https://gudhub.com/docs/rest-api/web-sockets/#ws-broadcast-to-app-subscribers)

This request is different from the first one, which sends a message to **all users subscribed to one specific app**.

### Request [#](https://gudhub.com/docs/rest-api/web-sockets/#request-1)

| Request Method | Content Type | Request URL |
| :-- | :-- | :-- |
| `POST` | `Form Data` | `https://gudhub.com/GudHub/ws/broadcast-to-app-subscribers` |

The request contains a data object with a message inside, an access token, and an application with recipient users.

| Property | Type | Description |
| :-- | :-- | :-- |
| data | `object` | _any data that needs to be transferred_ |
| token | `string` | _sender's token for access to the service_ |
| app\_id | `number` | _application whose subscribers are to be notified_ |

_**Example:**_

Copy

```json
app_id: 178
data: {some_data: ‘here’,…}
token: "xDDdP3FhfYamgo8XEqdrtgfhyjq4hg2A443zTL6fyRNvGSvuQoxXGCS"
```

### Response [#](https://gudhub.com/docs/rest-api/web-sockets/#response-1)

It returns all the data that was sent, the AP, and the sender ID in the initialized app that was created when that user first signed up.

Copy

```json
api: "/ws/broadcast-to-app-user"
app_id: 178
response: {some_data: ‘here’,…}
token: "xxDDdP3FhfYamgo8XEqdrtgfhyjq4hg2A443zTL6fyRNvGSvuQoxXGCS"
```

### WebSocket Message [#](https://gudhub.com/docs/rest-api/web-sockets/#websocket-message-1)

In case of this request, **all users which subscribed on the specific application** will receive the web socket message. It contains all the same data as the response to the request, as well as the sender's ID.

Copy

```json
api: "/ws/broadcast-to-app-user"
app_id: 178
response: {some_data: ‘here’,…}
token: "xDDdP3FhfYamgo8XEqdrtgfhyjq4hg2A443zTL6fyRNvGSvuQoxXGCS"
user_id: 1
```

### Status Code [#](https://gudhub.com/docs/rest-api/web-sockets/#status-code-1)

| Name | Description |
| :-- | :-- |
| 200 | all users received the message |
