---
title: Publishing
summary: >-
  Publishing sends messages to <a
  href="https://www.fastly.com/documentation/learning/concepts/real-time-messaging/fanout">Fanout</a>
  subscribers. Fanout is designed to be <a
  href="https://pushpin.org/docs/protocols/grip/">GRIP-compatible</a>, such that
  <code>https://api.fastly.com/service/{service_id}</code> can be used as a GRIP
  URL in application configurations.
url: https://www.fastly.com/documentation/reference/api/publishing
---

Publishing sends messages to <a href="https://www.fastly.com/documentation/learning/concepts/real-time-messaging/fanout">Fanout</a> subscribers. Fanout is designed to be <a href="https://pushpin.org/docs/protocols/grip/">GRIP-compatible</a>, such that <code>https://api.fastly.com/service/{service_id}</code> can be used as a GRIP URL in application configurations.

## Data model

| Field | Type | Description |
|-------|------|-------------|
| `body` | string | The response body as a string. |
| `body-bin` | string | The response body as a base64-encoded binary blob. |
| `code` | integer | The HTTP status code. |
| `headers` | object | A map of arbitrary HTTP response headers to include in the response. |
| `reason` | string | The HTTP status string. Defaults to a string appropriate for <code>code</code>. |

## Data model

| Field | Type | Description |
|-------|------|-------------|
| `content` | string | A fragment of body data as a string. |
| `content-bin` | string | A fragment of body data as a base64-encoded binary blob. |

## Data model

| Field | Type | Description |
|-------|------|-------------|
| `channel` | string | The channel to publish the message on. |
| `formats` | object | Transport-specific message payload representations to be used for delivery. At least one format (<code>http-response</code>, <code>http-stream</code>, and/or <code>ws-message</code>) must be specified. Messages are only delivered to subscribers interested in the provided formats. For example, the <code>ws-message</code> format will only be sent to WebSocket clients. |
| `id` | string | The ID of the message. |
| `prev-id` | string | The ID of the previous message published on the same channel. |

## Data model

| Field | Type | Description |
|-------|------|-------------|
| `items` | array | The messages to publish. |

## Data model

| Field | Type | Description |
|-------|------|-------------|
| `content` | string | The content of a WebSocket <code>TEXT</code> message. |
| `content-bin` | string | The base64-encoded content of a WebSocket <code>BINARY</code> message. |

## API endpoints

### Send messages to Fanout subscribers

**POST** `/service/{service_id}/publish/`

Send one or more messages to <a href="https://www.fastly.com/documentation/learning/concepts/real-time-messaging/fanout">Fanout</a> subscribers. Each message specifies a channel, and Fanout will deliver the message to all subscribers of its channel.

<strong>IMPORTANT:</strong> For compatibility with GRIP, this endpoint requires a trailing slash, and the API token may be provided in the <code>Authorization</code> header (instead of the <code>Fastly-Key</code> header) using the <code>Bearer</code> scheme.

**Parameters:**

| Name | Type | In | Required | Description |
|------|------|----|---------|--------------|
| `service_id` | string | path | Yes | Alphanumeric string identifying the service. |
