Streaming & Server-Sent Events (SSE)

Consume Server-Sent Events (SSE) and chunked response events with the client's async generator.


1. Consuming Event Streams (api.stream())

api.stream() returns an AsyncGenerator<StreamEvent>. SSE fields may include data, event, and id:

streaming.ts
typescript
import { createClient } from 'react-native-fetch-client';

const api = createClient({ baseURL: 'https://api.example.com' });

for await (const event of api.stream('/events')) {
  console.log(event.data);
}

For multipart uploads and download callbacks, see the uploads and downloads guide. Streaming requires a runtime with compatible Fetch stream support.