← tests

stream

A response written in parts as it is produced, rather than serialised whole and sent with its length.

Comparable across every framework. The rows are items.medium's, so the difference from json.medium is the streaming path and a write per row.

testheftrequestbasewhat differs from the base
stream.ndjson3GET /stream/itemsjson.mediumthe rows written one per line as they are produced, with no content length

stream.ndjson

heft 3

base json.mediumbase of sse.medium

items.medium's 89 rows written one per line as application/x-ndjson. There is no Content-Length, which is what shows the body left in parts rather than buffered. Read against json.medium, the difference is the framework's streaming path and a write per row.

Request

GET /stream/items

No body.

Expected response

HTTP 200
content-typematches /^application\/x-ndjson/
content-lengthis absent

payload items.medium, one row per line

{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true}
{"id":2,"name":"brass-hinge-5716","category":"garden","priceCents":17577,"inStock":true}
{"id":3,"name":"linen-ring-6971","category":"kitchen","priceCents":5540,"inStock":true}
{"id":4,"name":"copper-bolt-9217","category":"outdoor","priceCents":11562,"inStock":true}
{"id":5,"name":"linen-lamp-8288","category":"office","priceCents":1413,"inStock":true}
{"id":6,"name":"copper-pan-9308","category":"tools","priceCents":10795,"inStock":true}
{"id":7,"name":"slate-seed-3051","category":"garden","priceCents":9667,"inStock":false}
{"id":8,"name":"oak-lamp-8662","category":"kitchen","priceCents":18032,"inStock":fal
… 7,915 bytes total

Compared line by line, each line as parsed JSON.

Test source, tests/stream/ndjson.ts
tests/stream/ndjson.tsopen on GitHub →
import { performanceTest } from "#kit";
import { stream } from "#payloads";

const path = "/stream/items";

export default performanceTest({
  id: { family: "stream", name: "ndjson" },
  path,
  base: "json.medium",
  varies: "streaming",
  heft: 3,
  about:
    "items.medium's 89 rows written one per line as application/x-ndjson. " +
    "There is no Content-Length, which is what shows the body left in parts " +
    "rather than buffered. Read against json.medium, the difference is the " +
    "framework's streaming path and a write per row.",

  request: (c) => c.get(path).okWith(stream).hasHeader("content-type", /^application\/x-ndjson/).noHeader("content-length"),
});