Skip to main content

Overview

ofetch supports Server-Sent Events (SSE) through the stream response type, allowing you to consume real-time event streams from your server.

Basic Usage

How It Works

From src/fetch.ts:224-227:
When responseType: 'stream' is set:
  1. ofetch skips automatic parsing
  2. Returns the raw ReadableStream from response.body
  3. Allows manual chunk processing

Response Types

From src/types.ts:123-135:
Setting responseType: 'stream' returns a ReadableStream<Uint8Array>.

SSE Example from README

From README.md:294-307:

Common Use Cases

Real-Time Notifications

Chat Messages

Progress Updates

Parsing SSE Format

Cancelling Streams

With Custom Instances

TypeScript Support

Detection of Response Type

From src/fetch.ts:208-213:
You can also let ofetch detect SSE automatically by setting the response Content-Type: text/event-stream header on your server, though explicit responseType: 'stream' is recommended for SSE.