Nexus API Reference

StreamingResponse
in package

FinalYes
Tags
psalm-api

Static factories for streaming responses. The body is an IteratorStream that pulls chunks per read(). Server adapters MUST honour read+flush per chunk for SSE/NDJSON to deliver incrementally.

Table of Contents

Methods

file()  : ResponseInterface
fromGenerator()  : ResponseInterface
ndjson()  : ResponseInterface
Each item becomes one newline-delimited JSON object.
sse()  : ResponseInterface
Server-Sent Events. Each event is an array with keys: id?, event?, data, retry?.

Methods

file()

public static file(string $path[, string|null $contentType = null ]) : ResponseInterface
Parameters
$path : string
$contentType : string|null = null
Return values
ResponseInterface

fromGenerator()

public static fromGenerator(Generator $chunks[, int $status = 200 ][, array<string, string> $headers = [] ]) : ResponseInterface
Parameters
$chunks : Generator
$status : int = 200
$headers : array<string, string> = []
Return values
ResponseInterface

ndjson()

Each item becomes one newline-delimited JSON object.

public static ndjson(iterable<string|int, mixed> $items[, callable(mixed): string|null $encoder = null ]) : ResponseInterface
Parameters
$items : iterable<string|int, mixed>
$encoder : callable(mixed): string|null = null

Custom encoder. Defaults to json_encode.

Tags
psalm-suppress

MixedAssignment ndjson accepts heterogeneous items by design

Return values
ResponseInterface

sse()

Server-Sent Events. Each event is an array with keys: id?, event?, data, retry?.

public static sse(iterable<string|int, array{data: string, event?: string, id?: string, retry?: int}> $events) : ResponseInterface
Parameters
$events : iterable<string|int, array{data: string, event?: string, id?: string, retry?: int}>
Return values
ResponseInterface

        
On this page

Search results