ZestySwiftContentEndpointWrapper is a wrapper library that allows you to easily access your data from your Zesty.io website
- Installing ZestySwiftContentEndpointWrapper
- Initialization
- Using Basic JSON API
- Using Custom JSON Endpoints
- Example Project
ZestySwiftContentEndpointWrapper uses Cocoapods.
Simply add
pod 'ZestySwiftContentEndpointWrapper'
pod 'SwiftyJSON' # required for custom JSON Endpoints
to your Podfile. (Example Podfile)
For example, creating a ZestyAPI Object for your website http://burger.zesty.site
// Create the ZestyAPI Object
let zesty = ZestySwiftContentEndpointWrapper(url: "http://burger.zesty.site")
- note: If your website does not have an SSL Certificate (HTTPS), you will need to configure your app to allow for non HTTPS Calls. How to change this setting
- Enable the Basic JSON API in Config
- Get the zuid for the item / array you are looking for
- Use the according function (
getItem
orgetArray
)
Zuid Meanings and Functions to Use
- Any zuid that starts with a 6 is an array of items (use
getArray
) - Any zuid that starts with a 7 is an object (use
getItem
)
Gets a [String : String]
json data for the specific zuid.
You can find the zuid by looking at the Content Tab of Zesty.
For example, getting a specific item with zuid 6-9bfe5c-ntqxrs
// Create the ZestyAPI Object
let zesty = ZestySwiftContentEndpointWrapper(url: "http://burger.zesty.site")
let zuid = "6-9bfe5c-ntqxrs"
zesty.getItem(for: zuid, { (item) in
print(item) // item is a [String : String] dictionary, in JSON Format
}
Gets a [[String : String]]
array of json data for the specific zuid.
You can find the zuid by looking at the Content Tab of Zesty.
For example, getting a specific item with zuid 7-9bfe5c-ntqxrs
// Create the ZestyAPI Object
let zesty = ZestySwiftContentEndpointWrapper(url: "http://burger.zesty.site")
let zuid = "7-9bfe5c-ntqxrs"
zesty.getArray(for: zuid, { (items) in
for item in items {
print(item) // item is a [String : String] dictionary, in JSON Format
}
}
Gets a JSON object for the endpoint and parameters specified.
- note: ZestyAPI uses SwiftyJSON to handle JSON objects. Make sure you add
pod 'SwiftyJSON'
to yourPodfile
in order to use the data returned. - The returned JSON object's methods reference can be found here.
- If you want to use a different type of JSON parsing, the raw data can be extracted from the JSON object using
json.rawString(options: [.castNilToNSNull: true])
. More information on extracting the raw JSON String can be found here
A full tutorial to create your own custom JSON Endpoints through the Zesty Interface can be found here
For example, using the custom endpoint menulist
(Including the extension is only necessary for different file types ; .json is otherwise implied)
// Create the ZestySwiftContentEndpointWrapper Object
let zesty = ZestySwiftContentEndpointWrapper(url: "http://burger.zesty.site")
let endpoint = "menulist"
let parameters = ["location" : "San Diego"]
getCustomData(from: endpoint, params: parameters, { (json) in
print(item) // item is a [String : String] dictionary, in JSON Format
}
To help you get started, we've also made an example project
Ronak Shah for Zesty.io
ZestySwiftContentEndpointWrapper is available under the MIT license. See the LICENSE file for more info.