Body
An HTTP request body.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
struct Body
This object encapsulates the difference between streamed HTTP request bodies and those bodies that are already entirely in memory.
An HTTP request body.
struct Body
This object encapsulates the difference between streamed HTTP request bodies and those bodies that are already entirely in memory.
import AsyncHTTPClient
This package provides simple HTTP Client library built on top of SwiftNIO.
struct HTTPClientRequest
A representation of an HTTP request for the Swift Concurrency HTTPClient API.
init(url: String)
var body: Body?
The request body, if any.
var headers: HTTPHeaders
The request headers.
var method: HTTPMethod
The request method.
var tlsConfiguration: TLSConfiguration?
Request-specific TLS configuration, defaults to no request-specific TLS configuration.
var url: String
The request URL, including scheme, hostname, and optionally port.
mutating func setBasicAuth(username: String, password: String)
Set basic auth for a request.
protocol AsyncSequence<Element, Failure>
A type that provides asynchronous, sequential, iterated access to its elements.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Escapable
protocol Sendable
static func bytes(_ byteBuffer: ByteBuffer) -> HTTPClientRequest.Body
Create an Body
from a ByteBuffer
.
@preconcurrency static func bytes<Bytes>(_ bytes: Bytes) -> HTTPClientRequest.Body where Bytes : RandomAccessCollection, Bytes : Sendable, Bytes.Element == UInt8
Create an Body
from a RandomAccessCollection
of bytes.
@preconcurrency static func bytes<Bytes>(_ bytes: Bytes, length: Length) -> HTTPClientRequest.Body where Bytes : Sendable, Bytes : Sequence, Bytes.Element == UInt8
Create an Body
from a Sequence
of bytes.
@preconcurrency static func bytes<Bytes>(_ bytes: Bytes, length: Length) -> HTTPClientRequest.Body where Bytes : Collection, Bytes : Sendable, Bytes.Element == UInt8
Create an Body
from a Collection
of bytes.
@preconcurrency static func stream<SequenceOfBytes>(_ sequenceOfBytes: SequenceOfBytes, length: Length) -> HTTPClientRequest.Body where SequenceOfBytes : Sendable, SequenceOfBytes : AsyncSequence, SequenceOfBytes.Element == ByteBuffer
Create an Body
from an AsyncSequence
of ByteBuffer
s.
@preconcurrency static func stream<Bytes>(_ bytes: Bytes, length: Length) -> HTTPClientRequest.Body where Bytes : Sendable, Bytes : AsyncSequence, Bytes.Element == UInt8
Create an Body
from an AsyncSequence
of bytes.
func makeAsyncIterator() -> AsyncIterator
struct AsyncIterator
struct Length
The length of a HTTP request body.
typealias Element = ByteBuffer
func allSatisfy(_ predicate: (Self.Element) async throws -> Bool) async rethrows -> Bool
Returns a Boolean value that indicates whether all elements produced by the asynchronous sequence satisfy the given predicate.
func collect(upTo maxBytes: Int) async throws -> ByteBuffer
Accumulates an AsyncSequence
of ByteBuffer
s into a single ByteBuffer
.
func collect(upTo maxBytes: Int, into accumulationBuffer: inout ByteBuffer) async throws
Accumulates an AsyncSequence
of ByteBuffer
s into a single accumulationBuffer
.
@preconcurrency func compactMap<ElementOfResult>(_ transform: @escaping (Self.Element) async -> ElementOfResult?) -> AsyncCompactMapSequence<Self, ElementOfResult>
Creates an asynchronous sequence that maps the given closure over the asynchronous sequence’s elements, omitting results that don’t return a value.
@preconcurrency func compactMap<ElementOfResult>(_ transform: @escaping (Self.Element) async throws -> ElementOfResult?) -> AsyncThrowingCompactMapSequence<Self, ElementOfResult>
Creates an asynchronous sequence that maps an error-throwing closure over the base sequence’s elements, omitting results that don’t return a value.
func contains(_ search: Self.Element) async rethrows -> Bool
Returns a Boolean value that indicates whether the asynchronous sequence contains the given element.
func contains(where predicate: (Self.Element) async throws -> Bool) async rethrows -> Bool
Returns a Boolean value that indicates whether the asynchronous sequence contains an element that satisfies the given predicate.
@preconcurrency func drop(while predicate: @escaping (Self.Element) async -> Bool) -> AsyncDropWhileSequence<Self>
Omits elements from the base asynchronous sequence until a given closure returns false, after which it passes through all remaining elements.
func dropFirst(_ count: Int = 1) -> AsyncDropFirstSequence<Self>
Omits a specified number of elements from the base asynchronous sequence, then passes through all remaining elements.
@preconcurrency func filter(_ isIncluded: @escaping (Self.Element) async -> Bool) -> AsyncFilterSequence<Self>
Creates an asynchronous sequence that contains, in order, the elements of the base sequence that satisfy the given predicate.
func first(where predicate: (Self.Element) async throws -> Bool) async rethrows -> Self.Element?
Returns the first element of the sequence that satisfies the given predicate.
@preconcurrency func flatMap<SegmentOfResult>(_ transform: @escaping (Self.Element) async throws -> SegmentOfResult) -> AsyncThrowingFlatMapSequence<Self, SegmentOfResult> where SegmentOfResult : AsyncSequence
Creates an asynchronous sequence that concatenates the results of calling the given error-throwing transformation with each element of this sequence.
@preconcurrency func flatMap<SegmentOfResult>(_ transform: @escaping (Self.Element) async -> SegmentOfResult) -> AsyncFlatMapSequence<Self, SegmentOfResult> where SegmentOfResult : AsyncSequence, Self.Failure == SegmentOfResult.Failure
Creates an asynchronous sequence that concatenates the results of calling the given transformation with each element of this sequence.
@preconcurrency func flatMap<SegmentOfResult>(_ transform: @escaping (Self.Element) async -> SegmentOfResult) -> AsyncFlatMapSequence<Self, SegmentOfResult> where SegmentOfResult : AsyncSequence, SegmentOfResult.Failure == Never
Creates an asynchronous sequence that concatenates the results of calling the given transformation with each element of this sequence.
@preconcurrency func flatMap<SegmentOfResult>(_ transform: @escaping (Self.Element) async -> SegmentOfResult) -> AsyncFlatMapSequence<Self, SegmentOfResult> where SegmentOfResult : AsyncSequence, Self.Failure == Never, SegmentOfResult.Failure == Never
Creates an asynchronous sequence that concatenates the results of calling the given transformation with each element of this sequence.
@preconcurrency func map<Transformed>(_ transform: @escaping (Self.Element) async -> Transformed) -> AsyncMapSequence<Self, Transformed>
Creates an asynchronous sequence that maps the given closure over the asynchronous sequence’s elements.
@preconcurrency func map<Transformed>(_ transform: @escaping (Self.Element) async throws -> Transformed) -> AsyncThrowingMapSequence<Self, Transformed>
Creates an asynchronous sequence that maps the given error-throwing closure over the asynchronous sequence’s elements.
@warn_unqualified_access func max(by areInIncreasingOrder: (Self.Element, Self.Element) async throws -> Bool) async rethrows -> Self.Element?
Returns the maximum element in the asynchronous sequence, using the given predicate as the comparison between elements.
@warn_unqualified_access func min(by areInIncreasingOrder: (Self.Element, Self.Element) async throws -> Bool) async rethrows -> Self.Element?
Returns the minimum element in the asynchronous sequence, using the given predicate as the comparison between elements.
func prefix(_ count: Int) -> AsyncPrefixSequence<Self>
Returns an asynchronous sequence, up to the specified maximum length, containing the initial elements of the base asynchronous sequence.
@preconcurrency func prefix(while predicate: @escaping (Self.Element) async -> Bool) rethrows -> AsyncPrefixWhileSequence<Self>
Returns an asynchronous sequence, containing the initial, consecutive elements of the base sequence that satisfy the given predicate.
func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Self.Element) async throws -> Result) async rethrows -> Result
Returns the result of combining the elements of the asynchronous sequence using the given closure.
func reduce<Result>(into initialResult: Result, _ updateAccumulatingResult: (inout Result, Self.Element) async throws -> Void) async rethrows -> Result
Returns the result of combining the elements of the asynchronous sequence using the given closure, given a mutable initial value.