> ## Documentation Index
> Fetch the complete documentation index at: https://hitspec.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Server-Sent Events (SSE)

> Test Server-Sent Events endpoints with hitspec.

hitspec can test Server-Sent Events (SSE) endpoints. SSE is a standard for servers to push real-time updates to clients over a single HTTP connection.

When hitspec detects a `text/event-stream` Content-Type in a response, it automatically parses the SSE events and makes them available in the test results. Events are shown in verbose console output and returned in JSON/API results.

## Basic Usage

Connect to an SSE endpoint and assert on the events received:

```http theme={null}
### Listen to event stream
# @name eventStream

GET {{baseUrl}}/events
Accept: text/event-stream

>>>
expect status 200
expect header Content-Type contains "text/event-stream"
<<<
```

## How It Works

1. hitspec sends the HTTP request normally (the `Accept: text/event-stream` header is set by your test file).
2. The server responds with `Content-Type: text/event-stream` and a body containing SSE-formatted events.
3. hitspec detects the content type and parses the response body into structured events.
4. Each event has optional `id`, `type`, and `data` fields per the SSE specification.
5. Parsed events appear in verbose output and in the JSON/API result under `sseEvents`.

## Configuration

Control how long hitspec listens for events using the `@timeout` directive:

```http theme={null}
### Listen for 5 seconds
# @name longStream
# @timeout 5000

GET {{baseUrl}}/events
Accept: text/event-stream

>>>
expect status 200
<<<
```

## Verbose Output

Run with `--verbose` to see parsed SSE events in the console:

```
  ✓ eventStream (234ms)
    SSE Events: 3 received
      [1] message: hello
      [2] update: {"count":42}
      [3] message: goodbye
```

## Multi-line Data

SSE events with multiple `data:` lines are joined with newlines, per the SSE specification:

```http theme={null}
### Multi-line event data

GET {{baseUrl}}/events
Accept: text/event-stream

>>>
expect status 200
<<<
```

A server response like:

```
data: line one
data: line two
data: line three

```

Produces a single event with `data` equal to `"line one\nline two\nline three"`.
