Resources
-
A set of logically connected RESTful resources. Resources within a service share caching, configuration, and a “same URL → same resource” uniqueness guarantee.
You will typically create a separate instance of
Service
for each REST API you use. You can either subclassService
or encapsulte it inside a wrapper. Regardless, to reap the benefits of Siesta, you’ll want to ensure that all the observers of an API share a single instance.You can optionally specify a
baseURL
, which allows you to get endpoints by path:service.resource("/foo")
. Specifying abaseURL
does not limit the service only to subpaths of that URL. Its one and only purpose is to be the starting point forresource(_:)
.Note that
See morebaseURL
is only a convenience, and is optional. If you want to group multiple base URLs in a singleService
instance, useresource(baseURL:path:)
. If you want to feed your service arbitrary URLs with no common root, useresource(absoluteURL:)
.Declaration
Swift
@objc(BOSService) open class Service : NSObject
-
An in-memory cache of a RESTful resource, plus information about the status of network requests related to it.
This class answers three basic questions about a resource:
- What is the latest data for the resource this device has retrieved, if any?
- Did the last attempt to load it result in an error?
- Is there a request in progress?
…and allows multiple observer to register to be notified whenever the answers to any of these questions changes.
See moreDeclaration
Swift
@objc(BOSResource) public final class Resource : NSObject
extension Resource: ConfigurationPatternConvertible
extension Resource: TypedContentAccessors
-
An HTTP entity. Consists of data content plus metadata about the content’s type and freshness.
Typically extracted from an HTTP message body.
See moreDeclaration
-
Declaration
Swift
public struct Configuration
-
A type that can serve as a URL matcher for service configuration.
Siesta provides implementations of this protocol for
String
(for glob-based matching) andResource
(to configure one specific resource).See also
Service.configure(...)
See also
String.configurationPattern(for:)
See also
Resource.configurationPattern(for:)
Declaration
Swift
public protocol ConfigurationPatternConvertible
-
Mixin that provides convenience accessors for the content of an optional contained entity.
Allows you to replace the following:
resource.latestData?.content as? String (resource.latestError?.entity?.content as? [String:AnyObject])?["error.detail"]
…with:
resource.text resource.latestError?.jsonDict["error.detail"]
You can extend this protocol to provide your own convenience accessors. For example:
extension TypedContentAccessors { var doorknob: UIDoorknob { return typedContent(ifNone: placeholderKnob) } }
Note that the sample code above is only a convenience accessor. It checks whether the entity already has a
See moreUIDoorknob
, but does not do any parsing to put aUIDoorknob
there in the first place. You’d need to pair this with a customResponseTransformer
that converts raw doorknob responses toUIDoorknob
s.Declaration
Swift
public protocol TypedContentAccessors