Lightweight networking toolkit with async/await, Combine, callback APIs, WebSockets, and built-in stubbing. Minimum platforms: iOS 13, watchOS 6, macOS 11, tvOS 13.
- In your
Package.swiftadd:
.package(url: "https://github.com/<your-org>/darwin-httpclient.git", from: "1.0.0")- Link the product:
.product(name: "HttpClient", package: "darwin-httpclient").
let client = RpcClient()
let endpoint = ApiEndpoint(path: "https://api.example.com/users", type: .get)
let result = await client.performAsync(
endpoint: endpoint,
headers: [.authorization: .bearer(token: "token")],
queryParams: ["page": "1"],
bodyData: nil
)- Combine:
RpcClient().get(path: "...", headers: [:], queryParams: [:])returnsAnyPublisher<ApiResponse, ApiError>. - Callbacks: use
IRpcCompletionClientmethods. - Retries: pass
RetryParams(count: 3, delay: { 1.0 })toperformAsync/getfor automatic retry logic.
- Prefer
PublishedWSClient: publishes incoming messages and connection state via Combine, keeps the connection alive (pingInterval), and auto-reconnects (reconnectInterval).WSClientis experimental.
- HTTP: wrap real clients with
RpcAsyncClientStubbable(client: RpcClient()); manage rules mappingApiEndpoint→ApiResponseviaupsertandremoveAllRules. - WebSocket:
PublishedStubbableWSClientlets you stub responses for outgoing messages. JSON bodies can be normalized withData.stableNormalizedJSONString.
All clients accept any HttpClientLogging; default is DefaultLogger.shared. Inject your own logger for production.
- Build
URLSessionConfigurationquickly withApiSessionConfigBuilder.buildConfig(timeoutForResponse:timeoutResourceInterval:disableCookieStorage:). - TLS pinning helpers live in
Sources/SSLPinning/; extendCertVerificationChallengewith your pinned certificates.
- Default:
swift test(Swift Testing). - Coverage:
swift test --enable-code-coverage. - iOS sim: find a booted device ID with
xcrun simctl list devices | rg Booted, then run:
xcodebuild test -scheme darwin-httpclient -destination "id=<SIM_ID>" -sdk iphonesimulator -skipPackagePluginValidation