apple / apple/swift-http-api-proposal

[HTTPClient] HTTPClient can not be used as an existential

Open
#55 2 comments 0 reactions 0 assignees View on GitHub
http-client kind/usability
Dominant language
Swift
Stars
66
Forks
21
Avg merge
7h 39m
Merged PRs (30d)
2

Description

This code fails to compile:

```swift
@available(macOS 26.2, *)
struct WhateverAPI {

let httpClient: any HTTPClient

func doWhatever() async throws -> String {
let request = HTTPRequest(method: .get, scheme: "https", authority: "www.example.com", path: "/foo")

try await self.httpClient.perform(
request: request,
body: nil,
configuration: .init(),
eventHandler: EventHandler()
) { response, reader in

}
}
}
```

Fails to compile:

```
http_client_library.swift:15:24: error: member 'perform' cannot be used on value of type 'any HTTPClient'; consider using a generic constraint instead [#ExistentialMemberAccess]
13 | let request = HTTPRequest(method: .get, scheme: "https", authority: "www.example.com", path: "/foo")
14 |
15 | try await self.httpClient.perform(
| `- error: member 'perform' cannot be used on value of type 'any HTTPClient'; consider using a generic constraint instead [#ExistentialMemberAccess]
16 | request: request,
17 | body: nil,
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.