push-stream-std

@push-stream-std/push-fetch (0.0.8)

Published 2026-07-21 03:58:26 +00:00 by Dvorak

Installation

@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm install @push-stream-std/push-fetch@0.0.8
"@push-stream-std/push-fetch": "0.0.8"

About this package

@push-stream-std/push-fetch

Fetch API as a push-stream source.

Published as @push-stream-std/push-fetch.

Synopsis

import { fetch } from '@push-stream-std/push-fetch';

fetch('https://jsonplaceholder.typicode.com/posts/1').pipe({
  write(data) { process.stdout.write(data); },
  end(err) { if (err) console.error(err); else process.stdout.write('\n'); },
  abort(err) { console.error('aborted:', err); },
  paused: false
});

Install

npm config set @push-stream-std:registry https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken "$PACKAGE_TOKEN"
npm install @push-stream-std/push-fetch

Why

Wraps the standard Fetch API as a push-stream source. The response body is streamed in chunks as Buffer objects. Supports all standard fetch options including method, headers, body, redirect, and credentials. Aborting the source via source.abort() cancels the underlying request using AbortController. HTTP errors (non-2xx status codes) are delivered as errors to the sink's end callback.

API

fetch(url, options)

  • url - string - The URL to fetch.
  • options.method - string (default: 'GET') - HTTP method.
  • options.headers - object (default: {}) - Request headers.
  • options.body - any (default: null) - Request body.
  • options.redirect - string (default: 'follow') - Redirect handling mode.
  • options.credentials - string (default: 'same-origin') - Credentials mode.

Returns a push-stream source. Pipe it to a sink to receive response body chunks (Buffer objects). Call source.abort(err) to cancel the request.

Tests

npm test

Tests cover text and JSON responses, HTTP error handling (500, 404), streaming chunked responses, custom fetch options, request abort, and backpressure with resume.

Requirements

Node.js 22 or later. ESM only.

Dependencies

Dependencies

ID Version
@push-stream-std/push-stream-base *

Keywords

push-stream stream fetch http https
Details
npm
2026-07-21 03:58:26 +00:00
0
SEE LICENSE IN LICENSE
latest
3.9 KiB
Assets (1)
Versions (5) View all
0.0.8 2026-07-21
0.0.7 2026-07-20
0.0.6 2026-07-20
0.0.5 2026-07-19
0.0.3 2026-07-19