-
Notifications
You must be signed in to change notification settings - Fork 2
New perform with protocols and make the default client a concrete type #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0ce07c7
New perform with protocols and make the default client a concrete type
guoye-zhang 6a4b7fd
Fix Linux
guoye-zhang 0a85579
Fix upload
guoye-zhang fcdbc35
Review comment
guoye-zhang 5f13540
Remove configureOptions closure
guoye-zhang a95ad88
Remove client certificate data
guoye-zhang fb6cd6f
Add docs and namespace capabilities
guoye-zhang 214531c
Format
guoye-zhang 6abed71
Remove conveniences
guoye-zhang 457f211
Review comments
guoye-zhang acd6ab2
Merge branch 'main' into new-perform
guoye-zhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift HTTP API Proposal open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the Swift HTTP API Proposal project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift HTTP API Proposal project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| @available(macOS 26.2, iOS 26.2, watchOS 26.2, tvOS 26.2, visionOS 26.2, *) | ||
| extension HTTPClient { | ||
| /// Performs an HTTP request and processes the response. | ||
| /// | ||
| /// This convenience method provides default values for `body` and `options` arguments, | ||
| /// making it easier to execute HTTP requests without specifying optional parameters. | ||
| /// | ||
| /// - Parameters: | ||
| /// - request: The HTTP request header to send. | ||
| /// - body: The optional request body to send. Defaults to no body. | ||
| /// - options: The options for this request. Defaults to an empty initialized `RequestOptions`. | ||
| /// - responseHandler: The closure to process the response. This closure is invoked | ||
| /// when the response header is received and can read the response body. | ||
| /// | ||
| /// - Returns: The value returned by the response handler closure. | ||
| /// | ||
| /// - Throws: An error if the request fails or if the response handler throws. | ||
| public func perform<Return: ~Copyable>( | ||
| request: HTTPRequest, | ||
| body: consuming HTTPClientRequestBody<RequestWriter>? = nil, | ||
| options: RequestOptions = .init(), | ||
| responseHandler: (HTTPResponse, consuming ResponseConcludingReader) async throws -> Return, | ||
| ) async throws -> Return { | ||
| return try await self.perform(request: request, body: body, options: options, responseHandler: responseHandler) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Sources/HTTPAPIs/Client/HTTPClientCapability+RequestOptions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift HTTP API Proposal open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the Swift HTTP API Proposal project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift HTTP API Proposal project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| /// The namespace for all protocols defining HTTP client capabilities. | ||
| @available(macOS 26.2, iOS 26.2, watchOS 26.2, tvOS 26.2, visionOS 26.2, *) | ||
| public enum HTTPClientCapability { | ||
| /// The request options protocol. | ||
| /// | ||
| /// Additional options supported by a subset of clients are defined in child | ||
| /// protocols to allow libraries to depend on a specific capabilities. | ||
| public protocol RequestOptions { | ||
| init() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from the earlier discussion: #60 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, let's go ahead with this for now then.