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 subclass Service 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 a baseURL does not limit the service only to subpaths of that URL. Its one and only purpose is to be the starting point for resource(_:).

    Note that baseURL is only a convenience, and is optional. If you want to group multiple base URLs in a single Service instance, use resource(baseURL:path:). If you want to feed your service arbitrary URLs with no common root, use resource(absoluteURL:).

    See more

    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 more

    Declaration

    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 more

    Declaration

    Swift

    public struct Entity<ContentType>
    extension Entity: TypedContentAccessors
  • Options which control the behavior of a Resource.

    See more

    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) and Resource (to configure one specific resource).

    See more

    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 UIDoorknob, but does not do any parsing to put a UIDoorknob there in the first place. You’d need to pair this with a custom ResponseTransformer that converts raw doorknob responses to UIDoorknobs.

    See more

    Declaration

    Swift

    public protocol TypedContentAccessors