StreamRequest
public protocol StreamRequest : NetworkRequest
A request for a steram is similar to a Request
, only that it does not send an HTTP request,
but asks for a web socket. Instead of a Response
that yields at most one value, it therefore
returns a Stream
which allows for receiving arbitrarily many values as well as sending values.
Apart from that, working with a stream request is very similar to working with an HTTP request.
It is also scheduled against an API represented by an HttpService
. However, the service’s
retriers as well as its headers are ignored. Still, the Service.process(_:)
method is called.
-
Defines the type of the values sent by the client to the peer. By default, this is set to
Void
, indicating unidirectional communication from the peer to the client.Declaration
Swift
associatedtype Message = Void
-
Defines the type of the values sent from the peer to the client.
Declaration
Swift
associatedtype Result
-
Encodes a message sent from the client to the peer into an appropriate format for WebSocket communication. There exist default implementations for the case where
Message
is of typeVoid
,Data
, orString
. In the first case, an error is thrown (asVoid
indicates unidirectional communication from the peer to the client). In the latter two cases, the returned value can be synthesized trivially.Parameters
message
The message to be sent from the client to the peer.
-
Decodes a message sent by the peer into the stream’s result type. There exist default implementations for result types
Void
,Data
andString
. In the former case, aVoid
value is returned no matter the message, in the latter two cases, the return value can be synthesized easily.Parameters
message
The message sent by the peer.
-
schedule(with:)
Extension methodSchedules the stream request against the API specified by the given HTTP service. The returned value is the stream over which messages can be sent (bidirectionally). Note that this method is very similar to
Request.schedule(with:)
.Declaration
Swift
public func schedule(with service: HttpService) -> Stream<Self>
Parameters
service
The service representing the API against which to schedule this request.