@metreeca/http - v0.1.1
    Preparing search index...

    Function protocol

    • Creates a protocol dispatching middleware.

      The generated middleware serves through handler every exchange targeting a URL with the given scheme and relays every other exchange to the wrapped fetch implementation. The schemes the platform already resolves keep flowing to it untouched, while the ones it doesn't, file or zip among them, are supplied by a handler, without call sites having to know which is which.

      Layers are stacked to serve several schemes from a single client; where two of them state the same scheme, the outermost one serves it.

      Handlers are Fetch implementations, so they report their outcome as a Response, streaming the body as it is asked for and reporting failures as an unsuccessful status rather than as a thrown error: status handling stays with the consumer, whether a resource was retrieved from the network or from a local store.

      Exchanges reach their handler exactly as they were submitted, never normalised as a Request object, so that a request carrying a body is passed on undisturbed.

      Parameters

      • scheme: string

        The URI scheme to be served, stated in lowercase and with no trailing colon; the scheme of a target URL is matched against it disregarding case

      • handler: {
            (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
            (input: string | Request | URL, init?: RequestInit): Promise<Response>;
        }

        The Fetch implementation serving scheme

          • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: RequestInfo | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

          • (input: string | Request | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: string | Request | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

      Returns Middleware

      A Middleware wrapping a Fetch implementation with one serving through handler every exchange targeting a URL with scheme

      If scheme is not a well-formed lowercase URI scheme