documentation/content/en/api/streaming.md

83 lines
2.4 KiB
Markdown
Raw Normal View History

---
title: Streaming API
2018-09-26 00:35:55 +02:00
description: How to use Mastodon's streaming API for live, real-time updates
menu:
docs:
parent: api
weight: 4
---
Your application can use a [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) endpoint to receive updates in real-time. Server-sent events is an incredibly simple transport method that relies entirely on chunked-encoding transfer, i.e. the HTTP connection is kept open and receives new data periodically.
Alternatively, a WebSocket connection can also be established.
2018-09-25 02:18:01 +02:00
## Server-sent events (HTTP)
### Endpoints
#### GET /api/v1/streaming/health
Returns `OK` when streaming service is fine
2018-10-06 01:28:20 +02:00
#### GET /api/v1/streaming/user
Returns events that are relevant to the authorized user, i.e. home timeline and notifications
2018-10-06 01:28:20 +02:00
#### GET /api/v1/streaming/public
Returns all public statuses
2018-10-06 01:28:20 +02:00
#### GET /api/v1/streaming/public/local
Returns all local statuses
2018-10-06 01:28:20 +02:00
#### GET /api/v1/streaming/hashtag?tag=:hashtag
2018-09-26 00:19:44 +02:00
Returns all public statuses for a particular hashtag
2018-10-06 01:28:20 +02:00
#### GET /api/v1/streaming/hashtag/local?tag=:hashtag
2018-09-26 00:19:44 +02:00
Returns all local statuses for a particular hashtag
2018-10-06 01:28:20 +02:00
#### GET /api/v1/streaming/list?list=:list_id
2018-09-26 00:19:44 +02:00
Returns statuses for a list
2018-10-06 01:28:20 +02:00
#### GET /api/v1/streaming/direct
Returns all direct messages
### Stream contents
The stream will contain events as well as heartbeat comments. Lines that begin with a colon (`:`) can be ignored by parsers, they are simply there to keep the connection open. Events have this structure:
```
event: name
data: payload
```
## WebSocket
For WebSockets, there is only one URL path (`/api/v1/streaming`). The access token as well as the endpoint you are interested in must be provided with query params, respectively `access_token` and `stream`. Query params `list` and `tag` are likewise supported for relevant endpoints.
Possible `stream` values:
- `user`
- `public`
- `public:local`
- `hashtag`
- `hashtag:local`
- `list`
- `direct`
## Event types
|Event|Description|What's in the payload|
|-----|-----------|---------------------|
2018-09-26 00:19:44 +02:00
|`update`|A new status has appeared|[Status]({{< relref "entities.md#status" >}})|
|`notification`|A new notification has appeared|[Notification]({{< relref "entities.md#notification" >}})|
|`delete`|A status has been deleted|ID of the deleted status|
|`filters_changed`|Keyword filters have been changed||
The payload is JSON-encoded.
> **Note:** In case of `filters_changed` event, `payload` is not defined.