Skip to content

Abstract client evolution proposal#149

Open
guoye-zhang wants to merge 4 commits intoapple:mainfrom
guoye-zhang:proposal
Open

Abstract client evolution proposal#149
guoye-zhang wants to merge 4 commits intoapple:mainfrom
guoye-zhang:proposal

Conversation

@guoye-zhang
Copy link
Copy Markdown
Collaborator

Thank you @nakulbajaj for writing these up

@guoye-zhang guoye-zhang added area/documentation Improvements or additions to documentation. semver/none No version bump required. labels Apr 7, 2026
Copy link
Copy Markdown
Member

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round!

Comment thread NNNN-http-client-abstract.md Outdated
Comment thread NNNN-http-client-abstract.md Outdated
Comment thread NNNN-http-client-abstract.md
The `HTTPClient` protocol provides a single `perform` method that handles all HTTP interactions. The request and response metadata are expressed as `HTTPRequest` and `HTTPResponse` types, from the Swift HTTP types package. The protocol requires `Sendable`, ensuring all conforming clients are safe to share across concurrency domains.

```swift
public protocol HTTPClient<RequestOptions>: Sendable, ~Copyable, ~Escapable {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this potentially ~Copyable, ~Escapable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a callout "allows ~Copyable and ~Escapable types to conform to the protocol" but don't know how to explain why. Also not sure how to explain why it has to be Sendable. Hope we are not giving the impression that we are adopting new compiler features just for the sake of it.

Comment thread NNNN-http-client-abstract.md
Comment thread NNNN-http-client-abstract.md
Request bodies are supported via an `HTTPClientRequestBody`, which encapsulates a closure responsible for writing the request body, in a way that is either `seekable` or `restartable`. A `restartable` request body supports retries (for redirects and authentication challenges), and a `seekable` request body additionally supports resumable uploads. Trailer fields can also be returned from the closure.

```swift
public struct HTTPClientRequestBody<Writer: AsyncWriter & ~Copyable>: Sendable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this type is dependent on the client that will execute it, how can a user define a standalone request body?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTPClientRequestBody is just a wrapper of the restarting callback, and is not expected to be created or passed around as a standalone entity. It's similar to HTTPServerClosureRequestHandler on the server-side.

I would recommend users to build their own type to represent the body (or use existing types like Data / FileHandle) and convert them to HTTPClientRequestBody when calling perform.

Comment thread NNNN-http-client-abstract.md Outdated
Comment thread NNNN-http-client-abstract.md Outdated

The proposal consists of several interconnected modules, and the abstract API is defined as part of the `HTTPAPIs` module:
- **HTTPAPIs**: Protocol definitions for `HTTPClient` and shared types
- **NetworkTypes**: Currency types defined as needed for request option capabilities
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. Do we introduce a new Module here? What is this about? Where will it live?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more details. This are the currency types below HTTP, and I think it should eventually live in the toolchain.

Comment thread NNNN-http-client-concrete.md Outdated
Comment thread NNNN-http-client-abstract.md Outdated
Comment thread NNNN-http-client-abstract.md Outdated
Comment thread NNNN-http-client-abstract.md Outdated
Comment thread NNNN-http-client-abstract.md Outdated
}
```

Any code written against a generic `some HTTPClient` parameter can be tested by passing a `MockHTTPClient` instead of a real client, verifying requests and controlling responses without network access.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also mention that we built a conformance testing suite that works on an arbitrary concrete client?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do that in the concrete client proposal. This section is about testing the client user's logic through mocking a client.

@guoye-zhang guoye-zhang changed the title Add client evolution proposals Abstract client evolution proposal May 7, 2026
@guoye-zhang guoye-zhang added kind/proposal Proposals for review. http-client labels May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/documentation Improvements or additions to documentation. http-client kind/proposal Proposals for review. semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants