Stack

View as Markdown

Stack

Stack is instance for performing Contentstack Delivery API request.

NameTypeDescription
apiKey (required)String

API Key is a unique key assigned to each stack.

deliveryToken (required)String

Delivery Token is a read-only credential that you can create for different environments of your stack.

environment (required)String

Environment can be defined as one or more content delivery destinations

host String

The domain host to perform requests against.

region String

Region refers to the location of the data centers where your organization’s data resides.

apiVersion string

Stack api version point.

branch String

Branch for the stack to get data from.

cachePolicy CachePolicy

CachePolicy allows you to cache request

jsonDecoder JSONDecoder

The JSONDecoder that the receiving client instance uses to deserialize JSON. The SDK will inject information about the locales to this decoder and use this information to normalize the fields dictionary of entries and assets.

contentType(uid:)

Get instance of ContentType to fetch content-types and schema or fetch entries of specific content-type.

NameTypeDescription
uidString

The UId of ContentType you want to fetch data,

let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<ENVIRNOMENT>")


stack.contentType()


stack.contentType(uid: "<CONTENT_TYPE_UID>")

asset(uid:)

Get instance of Asset to fetch Assets or fetch specific Asset.

NameTypeDescription
uidString

The UId of Asset you want to fetch data.

let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<ENVIRNOMENT>")


stack.asset()


stack.asset(uid: "<ASSET_UID>")

sync(_:syncTypes:then:)

The Initial Sync request performs a complete sync of your app data. It returns all the published entries and assets of the specified stack in response. The response also contains a sync_token, which you get in SyncStack, since this token is used to get subsequent delta updates later.

NameTypeDescription
syncStackSyncStack

The relevant SyncStack to perform the subsequent sync on. Defaults to a new empty instance of SyncStack.

syncTypesSyncableTypes

SyncableTypes that can be sync.

completion (required)

A handler which will be called on completion of the operation.

let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<ENVIRNOMENT>")

stack.sync { (result: Result<SyncStack, Error>) in

    switch result {

    case .success(let syncStack):


    case .failure(let error):


    }

}

let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<ENVIRNOMENT>")


let syncStack = SyncStack(paginationToken: paginationToken)

stack.sync(syncStack, then: { (result: Result<SyncStack, Error>) in

    switch result {

    case .success(let syncStack):


    case .failure(let error):


    }

}

let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<ENVIRNOMENT>")


let syncStack = SyncStack(syncToken: syncToken)

stack.sync(syncStack, then: { (result: Result<SyncStack, Error>) in

    switch result {

    case .success(let syncStack):


    case .failure(let error):


    }

}

let stack = Contentstack.stack(apiKey: "<API_KEY>", deliveryToken: "<DELIVERY_TOKEN>", environment: "<ENVIRNOMENT>")

stack.sync(syncTypes: [.publishType(.assetPublished)], then: { (result: Result<SyncStack, Error>) in

    switch result {

    case .success(let syncStack):


    case .failure(let error):


    }

}