Swift
Swift
Simple GET using REST
See more REST Examples
Demonstrates how to do a simple HTTP GET request using REST.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = CkoRest()!
// Connect to the REST server.
var bTls: Bool = true
var port: Int = 443
var bAutoReconnect: Bool = true
success = rest.connect(hostname: "my-store.com", port: port, tls: bTls, autoReconnect: bAutoReconnect)
var responseJson: String? = rest.fullRequestNoBody(httpVerb: "GET", uriPath: "/wp-json/wc/v1/products?consumer_key=YOUR_CONSUMER_KEY&consumer_secret=YOUR_CONSUMER_SECRET")
if rest.lastMethodSuccess != true {
print("\(rest.lastErrorText!)")
return
}
print("\(responseJson!)")
print("----")
// We can alternatively do this:
rest.clearAllQueryParams()
rest.addQueryParam(name: "consumer_key", value: "YOUR_CONSUMER_KEY")
rest.addQueryParam(name: "consumer_secret", value: "YOUR_CONSUMER_SECRET")
responseJson = rest.fullRequestNoBody(httpVerb: "GET", uriPath: "/wp-json/wc/v1/products")
if rest.lastMethodSuccess != true {
print("\(rest.lastErrorText!)")
return
}
print("\(responseJson!)")
}