Capacitor Stream HTTP

raw JSON →
0.1.0 verified Sat Apr 25 auth: no javascript

Capacitor plugin for native HTTP streaming on iOS and Android, version 0.1.0. Enables true chunk-by-chunk streaming for Server-Sent Events (SSE) and other streaming APIs, with support for custom headers, request body, and cancellation. Differentiates from standard fetch by leveraging native URLSession (iOS) and HttpURLConnection (Android) for efficient streaming that works behind proxy configurations on mobile devices. Does not support web platform; falls back to fetch API. Maintained by chatbox, licensed MIT.

error Error: Unsupported platform web
cause Using the plugin in a web (browser) environment where native APIs are not available.
fix
Use feature detection: if (Capacitor.getPlatform() !== 'web') { /* use plugin */ } else { /* fallback to fetch */ }
error TypeError: StreamHttp.startStream is not a function
cause Incorrect import: using default import instead of named import.
fix
Change to: import { StreamHttp } from 'capacitor-stream-http'
breaking Not supported on web platform; web builds will throw an error or silently fail.
fix Check if running on native platform before using this plugin, or fall back to fetch/ReadableStream for web.
deprecated No deprecations yet.
fix N/A
gotcha The startStream method returns an object with an 'id' property; you must store this ID to cancel the stream later.
fix Always destructure { id } from the result.
gotcha Event listeners (addListener) must be removed to prevent memory leaks; the plugin does not auto-remove them.
fix Store listener references and call removeAllListeners or removeListener when done.
npm install capacitor-stream-http
yarn add capacitor-stream-http
pnpm add capacitor-stream-http

Demonstrates how to listen for chunk events, start a GET stream, and cancel it after 5 seconds.

import { StreamHttp } from 'capacitor-stream-http';

// Listen for chunks
await StreamHttp.addListener('chunk', (data) => {
  console.log('Received chunk:', data.chunk);
});

// Start streaming
const { id } = await StreamHttp.startStream({
  url: 'https://api.example.com/stream',
  method: 'GET',
});

// After some time, cancel the stream
setTimeout(async () => {
  await StreamHttp.cancelStream({ id });
}, 5000);