-
Closure type handling
DataStreamRequest.Streamvalues.Declaration
Swift
public typealias Handler<Success, Failure> = (Stream<Success, Failure>) throws -> Void where Failure : Error -
Type encapsulating an
See moreEventas it flows through the stream, as well as aCancellationTokenwhich can be used to stop the stream at any time.Declaration
Swift
public struct Stream<Success, Failure> where Failure : Error -
Type representing an event flowing through the stream. Contains either the
See moreResultof processing streamedDataor the completion of the stream.Declaration
Swift
public enum Event<Success, Failure> where Failure : Error -
Value containing the state of a
See moreDataStreamRequestwhen the stream was completed.Declaration
Swift
public struct Completion -
Type used to cancel an ongoing stream.
See moreDeclaration
Swift
public struct CancellationToken -
URLRequestConvertiblevalue used to createURLRequests for this instance.Declaration
Swift
public let convertible: URLRequestConvertible -
Whether or not the instance will be cancelled if stream parsing encounters an error.
Declaration
Swift
public let automaticallyCancelOnStreamError: Bool -
Validates the
URLRequestandHTTPURLResponsereceived for the instance using the providedValidationclosure.Declaration
Swift
@discardableResult public func validate(_ validation: @escaping Validation) -> SelfParameters
validationValidationclosure used to validate the request and response.Return Value
The
DataStreamRequest. -
Produces an
InputStreamthat receives theDatareceived by the instance.Note
The
InputStreamproduced by this method must haveopen()called before being able to readData. Additionally, this method will automatically callresume()on the instance, regardless of whether or not the creating session hasstartRequestsImmediatelyset totrue.Declaration
Swift
public func asInputStream(bufferSize: Int = 1024) -> InputStream?Parameters
bufferSizeSize, in bytes, of the buffer between the
OutputStreamandInputStream.Return Value
The
InputStreambound to the internalOutboundStream.
-
Creates a
DataStreamPublisherfor this instance using the givenDataStreamSerializerandDispatchQueue.Declaration
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) public func publishStream<Serializer: DataStreamSerializer>(using serializer: Serializer, on queue: DispatchQueue = .main) -> DataStreamPublisher<Serializer.SerializedObject>Parameters
serializerDataStreamSerializerused to serialize the streamedData.queueDispatchQueueon which theDataRequest.Streamvalues will be published..mainby default.Return Value
The
DataStreamPublisher. -
Creates a
DataStreamPublisherfor this instance which uses aPassthroughStreamSerializerto streamDataunserialized.Declaration
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) public func publishData(queue: DispatchQueue = .main) -> DataStreamPublisher<Data>Parameters
queueDispatchQueueon which theDataRequest.Streamvalues will be published..mainby default.Return Value
The
DataStreamPublisher. -
Creates a
DataStreamPublisherfor this instance which uses aStringStreamSerializerto serialize streamDatavalues intoStringvalues.Declaration
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) public func publishString(queue: DispatchQueue = .main) -> DataStreamPublisher<String>Parameters
queueDispatchQueueon which theDataRequest.Streamvalues will be published..mainby default.Return Value
The
DataStreamPublisher. -
Creates a
DataStreamPublisherfor this instance which uses aDecodableStreamSerializerwith the provided parameters to serialize streamDatavalues into the provided type.Declaration
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) public func publishDecodable<T: Decodable>(type: T.Type = T.self, queue: DispatchQueue = .main, decoder: DataDecoder = JSONDecoder(), preprocessor: DataPreprocessor = PassthroughPreprocessor()) -> DataStreamPublisher<T>Parameters
typeDecodabletype to which to decode streamData. Inferred from the context by default.queueDispatchQueueon which theDataRequest.Streamvalues will be published..mainby default.decoderDataDecoderinstance used to decode streamData.JSONDecoder()by default.preprocessorDataPreprocessorwhich filters incoming streamDatabefore serialization.PassthroughPreprocessor()by default.Return Value
The
DataStreamPublisher.
-
Creates a
DataStreamTaskused toawaitstreams of serialized values.Declaration
Swift
public func streamTask() -> DataStreamTaskReturn Value
The
DataStreamTask.
-
Adds a
StreamHandlerwhich performs no parsing on incomingData.Declaration
Swift
@discardableResult public func responseStream(on queue: DispatchQueue = .main, stream: @escaping Handler<Data, Never>) -> SelfParameters
queueDispatchQueueon which to performStreamHandlerclosure.streamStreamHandlerclosure called asDatais received. May be called multiple times.Return Value
The
DataStreamRequest. -
Adds a
StreamHandlerwhich uses the providedDataStreamSerializerto process incomingData.Declaration
Swift
@discardableResult public func responseStream<Serializer: DataStreamSerializer>(using serializer: Serializer, on queue: DispatchQueue = .main, stream: @escaping Handler<Serializer.SerializedObject, AFError>) -> SelfParameters
serializerDataStreamSerializerused to process incomingData. Its work is done on theserializationQueue.queueDispatchQueueon which to performStreamHandlerclosure.streamStreamHandlerclosure called asDatais received. May be called multiple times.Return Value
The
DataStreamRequest. -
Adds a
StreamHandlerwhich parses incomingDataas a UTF8String.Declaration
Swift
@discardableResult public func responseStreamString(on queue: DispatchQueue = .main, stream: @escaping Handler<String, Never>) -> SelfParameters
queueDispatchQueueon which to performStreamHandlerclosure.streamStreamHandlerclosure called asDatais received. May be called multiple times.Return Value
The
DataStreamRequest. -
Adds a
StreamHandlerwhich parses incomingDatausing the providedDataDecoder.Declaration
Swift
@discardableResult public func responseStreamDecodable<T: Decodable>(of type: T.Type = T.self, on queue: DispatchQueue = .main, using decoder: DataDecoder = JSONDecoder(), preprocessor: DataPreprocessor = PassthroughPreprocessor(), stream: @escaping Handler<T, AFError>) -> SelfParameters
typeDecodabletype to parse incomingDatainto.queueDispatchQueueon which to performStreamHandlerclosure.decoderDataDecoderused to decode the incomingData.preprocessorDataPreprocessorused to process the incomingDatabefore it’s passed to thedecoder.streamStreamHandlerclosure called asDatais received. May be called multiple times.Return Value
The
DataStreamRequest.
-
A closure used to validate a request that takes a
URLRequestandHTTPURLResponseand returns whether the request was valid.Declaration
Swift
public typealias Validation = (_ request: URLRequest?, _ response: HTTPURLResponse) -> ValidationResult -
Validates that the response has a status code in the specified sequence.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate<S>(statusCode acceptableStatusCodes: S) -> Self where S : Sequence, S.Element == IntParameters
acceptableStatusCodesSequenceof acceptable response status codes.Return Value
The instance.
-
Validates that the response has a content type in the specified sequence.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate<S>(contentType acceptableContentTypes: @autoclosure @escaping () -> S) -> Self where S : Sequence, S.Element == StringParameters
contentTypeThe acceptable content types, which may specify wildcard types and/or subtypes.
Return Value
The request.
-
Validates that the response has a status code in the default acceptable range of 200…299, and that the content type matches any specified in the Accept HTTP header field.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate() -> SelfReturn Value
The instance.
View on GitHub
Install in Dash
DataStreamRequest Class Reference