Swift

ThingsOn HTTP API / Swift

Swift programlama dilini kullanarak platformdan veri sorgulamak için aşağıdaki örneği kullanabilirsiniz.

Read
import Foundation
let headers = [
"Authorization": "Basic [API_KEY]",
]
let request = NSMutableURLRequest(url: NSURL(string: "http://cloud.thingson.io:8086/query?db=[DB_NAME]&q=[QUERY]")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()