Skip to content

fetch-ndjson turns new line delimited JSON streaming responses retrieved using Fetch API into Generators that yield JSON

Notifications You must be signed in to change notification settings

mash/fetch-ndjson

Repository files navigation

fetch-ndjson

fetch-ndjson turns new line delimited JSON streaming responses retrieved using Fetch API into Generators that yield JSON.

Install

npm i fetch-ndjson

Usage

import ndjson from 'fetch-ndjson';

let res = await fetch(pathname);
let reader = res.body.getReader();
let gen = ndjson(reader);
while (true) {
  let { done, value } = await gen.next();
  console.log(`done=${done}, value=${JSON.stringify(value)}`);
  if (done) {
    return;
  }
}

About

fetch-ndjson turns new line delimited JSON streaming responses retrieved using Fetch API into Generators that yield JSON

Resources

Stars

Watchers

Forks

Packages

No packages published