UNPKG

@yoyo-org/progressive-json

Version:

Stream and render JSON data as it arrives - perfect for AI responses, large datasets, and real-time updates

45 lines (44 loc) 1.42 kB
/** * HTTP Adapter Interface for Progressive JSON * * This interface allows users to provide their own HTTP client implementation * (e.g., pre-configured Axios instances) instead of using the built-in fetch. */ export interface HttpAdapter { /** * Make a streaming HTTP request * @param url - The URL to request * @param options - Optional request configuration * @returns A readable stream of response chunks */ stream(url: string, options?: HttpAdapterOptions): Promise<ReadableStream<Uint8Array>>; } export interface HttpAdapterOptions { method?: string; headers?: Record<string, string>; body?: string | FormData | ArrayBuffer; signal?: AbortSignal; timeout?: number; } /** * Response interface for adapters that need to return additional metadata */ export interface HttpAdapterResponse { stream: ReadableStream<Uint8Array>; status: number; statusText: string; headers: Record<string, string>; ok: boolean; } /** * Extended adapter interface for more control over the response */ export interface ExtendedHttpAdapter { /** * Make a streaming HTTP request with full response metadata * @param url - The URL to request * @param options - Optional request configuration * @returns Response with stream and metadata */ request(url: string, options?: HttpAdapterOptions): Promise<HttpAdapterResponse>; }