Hyperlinkv0.8.0-beta.28

Hyperlink

Hyperlink.protocolHttpconstsrc/Hyperlink.ts:4094
(
  target?: number | string,
  serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
): Layer.Layer<RpcClient.Protocol>

Build an http client Protocol (Fetch + ndjson serialization) for an endpoint — the value you hand layerProtocol or connect. target is a port (3009http://${clientHost}:3009/rpc, Config host default "localhost"), a full url, or a same-origin path (default "/rpc"). The server/CLI transport; a browser should prefer protocolWebsocket (HTTP/1.1's ~6-connection cap starves streams — protocolHttp dies loudly in a browser).

Source src/Hyperlink.ts:409419 lines
export const protocolHttp = (
  target: number | string = "/rpc",
  serialization: Layer.Layer<RpcSerialization.RpcSerialization> = defaultSerialization,
): Layer.Layer<RpcClient.Protocol> => {
  // guard at the root: `http` / `connect` all build on this, so the browser footgun is closed for
  // every http-client path in one place.
  const build = (url: string): Layer.Layer<RpcClient.Protocol> =>
    Layer.merge(
      RpcClient.layerProtocolHttp({ url }).pipe(
        Layer.provide(serialization),
        Layer.provide(FetchHttpClient.layer),
      ),
      Layer.effectDiscard(dieIfHttpClientInBrowser),
    );
  // A bare port defers to the `clientHost` Config (layer build); a path / url stays sync.
  return typeof target === "number" || /^:\d+$/.test(target)
    ? Layer.unwrap(Effect.map(clientTargetUrl("http", target), build))
    : build(target);
};
Referenced by 3 symbols