An API request. Provides notification hooks about the status of the request, and allows cancellation.
Note that this represents only a single request, whereas
ResourceObservers receive notifications about all resource load requests, no matter who initiated them. Note also that these hooks are available for all requests, whereas
ResourceObservers only receive notifications about changes triggered by
Requestguarantees that it will call any given callback at most one time.
Callbacks are always called on the main thread.
NoteThere is no race condition between a callback being added and a response arriving. If you add a callback after the response has already arrived, the callback is still called as usual. In other words, when attaching a hook, you do not need to worry about where the request is in its lifecycle. Except for how soon it’s called, your hook will see the same behavior regardless of whether the request has not started yet, is in progress, or is completed.
public protocol Request : AnyObject
Information about a failed resource request.
Siesta can encounter errors from many possible sources, including:
- client-side encoding / request creation issues,
- network connectivity problems,
- protocol issues (e.g. certificate problems),
- server errors (404, 500, etc.), and
- client-side parsing and entity validation failures.
RequestErrorpresents all these errors in a uniform structure. Several properties preserve diagnostic information, which you can use to intercept specific known errors, but these diagnostic properties are all optional. They are not even mutually exclusive: Siesta errors do not break cleanly into HTTP-based vs. Error / NSError-based, for example, because network implementations may sometimes provide both an underlying
Errorand an HTTP diagnostic.
The one ironclad guarantee thatSee more
RequestErrormakes is the presence of a
public struct RequestError : Error