Networking Layer
Networking Layer is responsible for handling all network communication, providing a robust, flexible, and testable interface for making API requests, handling responses, managing errors, and processing data.
The key features of this networking layer include:
- A centralized OCNetworkManager for executing various types of network requests (data, decodable objects, downloads).
- Protocol-oriented design (OCNetworkManagerProtocol, OCRequestable, URLSessionProtocol, OCNetworkInterceptorProtocol) promoting flexibility and testability.
- An interception mechanism (OCNetworkInterceptorProtocol) allowing modification of requests and responses for tasks like authentication, logging, or custom error handling.
- A detailed error handling system with a custom OCNetworkError enum.
- Support for request retries with configurable limits and delays.
- Management of download tasks, including cancellation of active downloads.
Core Components
OCNetworkManager
The OCNetworkManager class is the primary orchestrator for all network operations. It encapsulates the logic for sending requests, processing responses, handling errors, and managing interceptors.
OCRequestable
The OCRequestable protocol is central to defining the specifics of a network request. It encapsulates all the information needed to construct a URLRequest.
OCNetworkInterceptor
Network Interceptor provides a powerful mechanism to intercept and modify requests before they are sent and process responses (or errors) before they are returned to the caller.
OCNetworkError
A comprehensive custom error enum that represents various failures that can occur within the networking layer.
OCHTTPStatusCode
An enum representing HTTP status codes. It provides a more descriptive and type-safe way to handle status codes compared to raw integers.