# Connect an HTTP server

> Connect to an HTTP server using Synnax.

The Synnax Driver talks to any device or service with an HTTP or HTTPS JSON API: REST endpoints on embedded devices, cloud telemetry APIs, monitoring endpoints, and IoT gateways. Bearer token, basic auth, and API key authentication are supported.

## Prerequisites

Before you can connect to an HTTP server, you will need to ensure that you have the following:

1. A [Synnax Core](https://docs.synnaxlabs.com/reference/core/quick-start) running on your network.
2. A [Synnax Driver](https://docs.synnaxlabs.com/reference/driver/get-started) running on your network. This Driver must be connected to the Core and able to reach your HTTP server.
3. The [Synnax Console](https://docs.synnaxlabs.com/reference/console/get-started) installed on your local machine.
4. An HTTP server running on your network that is reachable by the Driver.

## Supported operating systems

| Platform           | Status      |
| ------------------ | ----------- |
| Windows            | ✓ Supported |
| Linux              | ✓ Supported |
| NI Linux Real-Time | ✓ Supported |
| macOS              | ✓ Supported |
| Docker             | ✓ Supported |

> When running in a Docker container, ensure [the container has network access](https://docs.docker.com/get-started/docker-concepts/running-containers/publishing-ports/) to the HTTP server.

## Configuration parameters reference

| Parameter      | Type    | Required | Default | Description                                                                                                                                                             |
| -------------- | ------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`         | string  | Yes      | -       | Human-readable server name for identification in Console                                                                                                                |
| `rack`         | string  | Yes      | -       | Synnax Driver (rack) key that will connect to the HTTP server                                                                                                           |
| `host`         | string  | Yes      | -       | Host and port of the HTTP server (e.g., `192.168.1.100:8080` or `localhost:443`)                                                                                        |
| `secure`       | boolean | No       | `true`  | Use HTTPS (`true`) or HTTP (`false`)                                                                                                                                    |
| `timeout_ms`   | integer | No       | `100`   | Request timeout in milliseconds                                                                                                                                         |
| `verify_ssl`   | boolean | No       | `true`  | Whether to verify SSL/TLS certificates                                                                                                                                  |
| `auth`         | object  | No       | `none`  | The [configuration](https://docs.synnaxlabs.com/reference/driver/http/connect-server#authentication-reference) used to authenticate with the HTTP server                |
| `health_check` | object  | Yes      | -       | The [configuration](https://docs.synnaxlabs.com/reference/driver/http/connect-server#health-check-configuration) the Driver uses to track the health of the HTTP server |

> Setting `verify_ssl` to `false` should be used when the HTTP server does not have a verified SSL certificate, which is common for internal servers not connected to the public internet.

## Authentication reference

The HTTP driver supports four authentication methods. Authentication is configured at the device level and applied to every request.

None (default)

No authentication headers are added to requests.

```json
{ "type": "none" }
```

Bearer token

Adds an `Authorization: Bearer <token>` header to every request.

| Parameter | Type   | Required | Description            |
| --------- | ------ | -------- | ---------------------- |
| `token`   | string | Yes      | The bearer token value |

```json
{ "type": "bearer", "token": "my-secret-token" }
```

Basic (username and password)

Adds an `Authorization: Basic <credentials>` header using Base64 encoded `username:password`.

| Parameter  | Type   | Required | Description |
| ---------- | ------ | -------- | ----------- |
| `username` | string | Yes      | Username    |
| `password` | string | Yes      | Password    |

```json
{ "type": "basic", "username": "admin", "password": "secret" }
```

API key

Sends an API key as either a custom header or a query parameter.

| Parameter   | Type   | Required | Default | Description                                                       |
| ----------- | ------ | -------- | ------- | ----------------------------------------------------------------- |
| `key`       | string | Yes      | -       | The API key value                                                 |
| `send_as`   | string | Yes      | -       | How to send the key: `"header"` or `"query_param"`                |
| `header`    | string | No       | -       | Header name (required when `send_as` is `"header"`)               |
| `parameter` | string | No       | -       | Query parameter name (required when `send_as` is `"query_param"`) |

```json
{ "type": "api_key", "send_as": "header", "header": "X-API-Key", "key": "abc123" }
```

```json
{ "type": "api_key", "send_as": "query_param", "parameter": "api_key", "key": "abc123" }
```

## Health check configuration

The driver periodically checks whether the HTTP server is reachable. We recommend choosing a path that sends a very small response body if the server does not have a dedicated `/health`, `/status`, or `/ping` endpoint.

Health check parameters

| Parameter      | Type   | Required | Default     | Description                                                                                                                                   |
| -------------- | ------ | -------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `method`       | string | Yes      | -           | HTTP method for the health check (`"GET"` or `"POST"`)                                                                                        |
| `path`         | string | No       | `"/health"` | URL path to request                                                                                                                           |
| `headers`      | object | No       | -           | Additional headers to include                                                                                                                 |
| `query_params` | object | No       | -           | Query parameters to include                                                                                                                   |
| `body`         | string | No       | -           | Request body (POST only)                                                                                                                      |
| `response`     | object | No       | -           | Optional [response validation](https://docs.synnaxlabs.com/reference/driver/http/connect-server#response-validation-parameters) configuration |

Response validation parameters

When a `response` object is provided, the driver validates the response body against an expected value:

| Parameter             | Type   | Required | Description                                                                                            |
| --------------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------ |
| `pointer`             | string | Yes      | [JSON Pointer](https://datatracker.ietf.org/doc/html/rfc6901) into the response body (e.g., `/status`) |
| `expected_value_type` | string | Yes      | Type of the expected value: `string`, `number`, `boolean`, `null`                                      |
| `expected_value`      | JSON   | Yes      | The expected value at that pointer                                                                     |

## How-to

**Console**

[](https://synnax.nyc3.cdn.digitaloceanspaces.com/docs/device-drivers/http/connect-server/connect-server-dark.mp4#t=0.001)

**Python**

Connect to an HTTP server

```python
import synnax as sy

# Initialize Synnax client
client = sy.Synnax()

# Retrieve the embedded rack
rack = client.racks.retrieve_embedded_rack()

# Create the HTTP device
device = sy.http.Device(
    host="192.168.1.100:8080",
    secure=False,
    name="My HTTP Server",
    rack=rack.key,
    health_check=sy.http.HealthCheck(path="/health"),
)

# Create the device in Synnax
device = client.devices.create(device)

# Or retrieve by name
device = client.devices.retrieve(name="My HTTP Server")

print(f"Connected to HTTP server: {device.name}")
```

Connect with authentication

```python
import synnax as sy

client = sy.Synnax()
rack = client.racks.retrieve_embedded_rack()

# Bearer token authentication
device = sy.http.Device(
    host="api.example.com:443",
    secure=True,
    name="Authenticated API",
    rack=rack.key,
    auth={"type": "bearer", "token": "my-secret-token"},
)

device = client.devices.create(device)
```

Connect with health check validation

```python
import synnax as sy

client = sy.Synnax()
rack = client.racks.retrieve_embedded_rack()

device = sy.http.Device(
    host="192.168.1.100:8080",
    secure=False,
    name="My HTTP Server",
    rack=rack.key,
    health_check=sy.http.HealthCheck(
        method="GET",
        path="/health",
        response=sy.http.ExpectedResponse(
            pointer="/status",
            expected_value_type="string",
            expected_value="ok",
        ),
    ),
)

device = client.devices.create(device)
```

Disconnect server

```python
import synnax as sy

# Initialize Synnax client
client = sy.Synnax()

# Retrieve the device by name
device = client.devices.retrieve(
    name="My HTTP Server",
    ignore_not_found=True
)

if device is not None:
    # Delete the server
    client.devices.delete([device.key])
    print(f"Disconnected HTTP server: {device.name}")
else:
    print("Server not found")
```
