---
title: Formato dei messaggi
project: OpenSync
version: 1.0
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/opensync/1-0/reference/message-format/
updated: 2026-11-19T09:22:09.965Z
---

# Formato dei messaggi

> I campi dei messaggi che OpenSync invia ai client.

Ogni richiesta a `/sync/{channel}/` e ogni `notify` WebSocket diventa un messaggio JSON. I client ricevono lo stesso messaggio via [WebSocket](../websocket/) e [Server-Sent Events](../server-sent-events/).

## Esempio

```json
{"id":"24nb4004pu50d","type":"application/json","channel":"orders","method":"POST","headers":{"host":"sync.example.com","user-agent":"curl/8.7.1","accept":"*/*","content-type":"application/json","content-length":"27"},"ua":"","query":{},"body":{"id":1002,"status":"paid"},"ts":"2026-11-19T08:04:51.361Z","ip":"203.0.113.10","files":[]}
```

## Campi

| Campo | Tipo | Significato |
|---|---|---|
| `id` | stringa | Un ID univoco del messaggio. |
| `type` | stringa | Il tipo di contenuto della richiesta, senza parametri come `boundary`: `application/json`, `application/x-www-form-urlencoded`, `multipart/form-data`, `text/plain`… Vuoto per una richiesta senza corpo. Sempre `application/json` per un messaggio WebSocket. |
| `channel` | stringa | Il canale. |
| `method` | stringa | `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, oppure `SOCKET` per un messaggio WebSocket. |
| `headers` | oggetto | Gli header della richiesta, con i nomi in minuscolo. Vuoto per un messaggio WebSocket. |
| `ua` | stringa | Una forma breve del browser e del sistema presi dall'header `User-Agent`, per esempio `Mac Chrome`. Vuoto per script e strumenti come curl. |
| `query` | oggetto | Gli argomenti di query, come stringhe. |
| `body` | oggetto o stringa | JSON e dati dei moduli come oggetto, altri contenuti come testo, una stringa vuota senza corpo. |
| `ts` | stringa | Il momento in cui OpenSync ha ricevuto la richiesta (ISO 8601, UTC). |
| `ip` | stringa | L'indirizzo IP del mittente. |
| `files` | array | I file caricati. Leggi [Inviare file](../files/). |
| `dtcreated` | stringa | Solo mentre [Registrare tutte le richieste](../../guides/request-log/) è attivo: il momento in cui il messaggio è stato registrato. |

## Il messaggio init

Quando un client si connette, riceve per primo:

```json
{"type":"init","name":"Demo sync","version":1,"id":"OpenSync"}
```

| Campo | Significato |
|---|---|
| `type` | Sempre `init`. |
| `name` | Il nome dell'istanza indicato nella pagina **Setup**. |
| `version` | Il numero di versione di OpenSync, `1`. |
| `id` | Sempre `OpenSync`. |
