---
title: REST API Endpoints
slug: solutions/rest-api-endpoints
docTags: 
createdAt: 2024-11-05T15:45:11.922Z
---

The Topic Registry provides REST API endpoints for programmatic access to topic data. This enables integration with other tools or services.

**Important**: REST API endpoints require a secret key for authentication, set via the `X_LITMUS_KEY` environment variable during deployment. Include this key in the request headers as `X_LITMUS_KEY`. The default value is `change-me`.

## Available endpoints

**GET&#x20;**`/api/streaming/{topic}`: Server-Sent Events (SSE) streaming endpoint for a live topic data stream

- Example usage with **Curl/Postman**

![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/94VRwiUPKKJrxvl7SZBSV_image.png)

```bash
curl -N -H "X_LITMUS_KEY: your-secret-key" \
  "http://localhost:3000/api/streaming/devicehub.alias.sensor1.temperature"
```

- Example usage with **Javascript/Typescript**

```javascript
const eventSource = new EventSource('/api/streaming/your.topic.name', {
  headers: { X_LITMUS_KEY: 'your-secret-key' },
});

eventSource.onmessage = function (event) {
  const data = JSON.parse(event.data);
  console.log('Received:', data.value, 'at', new Date(data.timestamp));
};

eventSource.onerror = function (event) {
  console.error('Connection error:', event);
};
```

**POST&#x20;**`/api/subscribe`: Subscribe to a specific topic to receive real-time updates. Provide the topic name as a query parameter:

```bash
  POST /api/subscribe?topic=topic-name
```

You can set a timeout in milliseconds with the `timeout` parameter (maximum 60,000 ms):

```bash
  POST /api/subscribe?topic=topic-name&timeout=60000
```

:::hint{type="info"}
If the timeout is reached without any data being published, the subscription remains active. You can receive updates using the` GET /api/value` endpoint.
:::

![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/87z_l4RiYdctLj7ipdRES_step-16.png)

**GET&#x20;**`/api/value`: Retrieve the last stored value of a topic:

```bash
GET /api/value?topic=topic-name
```

![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/wfIt9x_NofKl17TH0wuUm_step-17.png)

These REST API endpoints provide a convenient way to access topic data programmatically, enabling seamless integration with external systems and services.

**Tip**: To get a list of real-time subscriptions, use:

```bash
GET /api/subscribe
```

This endpoint returns all active subscriptions and their topics.

![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/BYUhwMp5oYK6YP5wu7S30_step-18.png)

