Swift
Swift
REST Auto Reconnect for Multiple Requests (dev.markitondemand.com)
See more REST Examples
Demonstrates how the autoReconnect argument to the Connect method is used.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()!
// This example demonstrates the usage of the autoReconnect argument to the Connect method.
// When autoReconnect is on, subsequent REST method calls will automatically re-connect
// if necessary, using the same information (domain/IP address, port number, and TLS).
var bTls: Bool = false
var port: Int = 80
var bAutoReconnect: Bool = true
success = rest.connect(hostname: "dev.markitondemand.com", port: port, tls: bTls, autoReconnect: bAutoReconnect)
// Get a stock quote:
success = rest.addQueryParam(name: "symbol", value: "AAPL")
var responseXml: String? = rest.fullRequestNoBody(httpVerb: "GET", uriPath: "/MODApis/Api/v2/Quote")
if rest.lastMethodSuccess != true {
print("\(rest.lastErrorText!)")
return
}
let xml = CkoXml()!
success = xml.load(xmlData: responseXml)
print("AAPL LastPrice: \(xml.getChildContent(tagPath: "LastPrice")!)")
// Get another stock quote. If a new HTTP connection is required,
// the REST object will automatically connect using the same parameters.
success = rest.addQueryParam(name: "symbol", value: "AMZN")
responseXml = rest.fullRequestNoBody(httpVerb: "GET", uriPath: "/MODApis/Api/v2/Quote")
if rest.lastMethodSuccess != true {
print("\(rest.lastErrorText!)")
return
}
success = xml.load(xmlData: responseXml)
print("AMZN LastPrice: \(xml.getChildContent(tagPath: "LastPrice")!)")
}