NetworkClient

public protocol NetworkClient

Protocol for sending network requests and handling responses.

  • Sends a URLRequest as is and completes with a NetworkResult. It returns a Disposable that can be disposed to cancel the request sent.

    Request lifecycle events are sent to the request interceptors and they are retried, when necessary, following the RequestInterceptor logic.

    Declaration

    Swift

    func sendRequest(_ request: URLRequest, completion: @escaping (NetworkResult) -> Void) -> any Disposable

    Parameters

    request

    the URLRequest that is sent in the URLSession.dataTask

    completion

    the block that is called once the request is completed either with a success or with an unretryable error

    Return Value

    the Disposable that can be used to dispose the request and cancel the dataTask and future retries.

  • Builds the given RequestBuilder and sends the resulting URLRequest, completing with a NetworkResult.

    Building happens in the client, so a malformed URL or any other build failure completes with .failure(.unknown) and returns an already-disposed Disposable — the completion is always called. This is the preferred entry point for custom (e.g. gzipped) requests: build with RequestBuilder and hand the builder here.

    Declaration

    Swift

    func sendRequest(_ request: RequestBuilder, completion: @escaping (NetworkResult) -> Void) -> any Disposable

    Parameters

    request

    the RequestBuilder describing the request to build and send.

    completion

    the block called once the request is completed, or immediately with a failure if it can’t be built.

    Return Value

    the Disposable that can be used to cancel the request.

  • Creates a new NetworkClient from this instance which will use a specific logger.

    Declaration

    Swift

    func newClient(withLogger logger: LoggerProtocol) -> Self

    Parameters

    logger

    The logger that will be used for this instance

    Return Value

    A new NetworkClient instance.