rest-vir - v1.7.0
    Preparing search index...

    Function fetchStreamEndpoint

    • Send a request to an endpoint definition and return a ReadableStream instead of parsing the response body. This is useful for consuming SSE (Server-Sent Events) endpoints from frontend clients.

      Uses the same request-building and validation flow as fetchEndpoint, but skips response body and JSON validation.

      Type Parameters

      • const EndpointToFetch extends
            | typeof NoParam
            | Readonly<
                {
                    methods: _RequireAtLeastOne<Record<HttpMethod, boolean>, HttpMethod>;
                    path: `/${string}`;
                    requestDataShape: Shape | undefined;
                    responseDataShape: Shape | undefined;
                    service: { serviceName: any; serviceOrigin: string };
                },
            >

      Parameters

      • endpoint: EndpointToFetch extends EndpointDefinition
            ? EndpointToFetch
            : {
                methods: _RequireAtLeastOne<Record<HttpMethod, boolean>, HttpMethod>;
                path: `/${string}`;
                requestDataShape: Shape | undefined;
                responseDataShape: Shape | undefined;
                searchParamsShape: Shape<unknown> | undefined;
                service: { serviceName: any; serviceOrigin: string };
            }
      • ...params: CollapsedFetchEndpointParams<EndpointToFetch>

      Returns Promise<FetchStreamEndpointOutput>

      import {fetchStreamEndpoint} from '@rest-vir/define-service';

      const result = await fetchStreamEndpoint(myService.endpoints['/my-sse-endpoint']);

      if (result.ok) {
      const reader = result.stream.getReader();
      }