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.swift add:
.package(url: "https://github.com/relux-works/swift-httpclient.git", from: "1.0.0")Link the product:
.product(name: "HttpClient", package: "swift-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). WSClient is experimental.
- HTTP: wrap real clients with
RpcAsyncClientStubbable(client: RpcClient()).- Recommended API for UI-test setup (less boilerplate):
await stubbable.upsert(stubs: [ .init(endpoint: loginEndpoint, response: loginResponse), .init(endpoint: feedEndpoint, queryParams: ["page": "1"], response: page1Response), .init( endpoint: searchEndpoint, queryParams: ["mode": "strict"], bodyData: payload, response: strictSearchResponse ) ])
- Fine-grained matching uses
RpcAsyncClientStubRule+RpcAsyncClientStubBodyMatcher(.any/.exact(Data?)). - Compatibility helpers are still available:
upsert(rule:...),upsert(rules:...),remove(rule:...),removeAllRules().
- Recommended API for UI-test setup (less boilerplate):
- 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
URLSessionConfigurationwithApiSessionConfigBuilder.buildConfig(timeoutForResponse:timeoutResourceInterval:disableCookieStorage:). - TLS pinning helpers live in
Sources/SSLPinning/; extendCertVerificationChallengewith your pinned certificates.
swift test
swift test --enable-code-coverage