Swift

ThingsOn HTTP API / Swift

Swift programlama dilini kullanarak platforma veri göndermek için aşağıdaki örneği kullanabilirsiniz.

Write
import Foundation
let headers = [
"Authorization": "Basic [API_KEY]",
]
let postData = NSData(data: "[TABLE_NAME] [FIELD_1=90],[FIELD_2=90],[FIELD_3=90]".data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: NSURL(string: "http://cloud.thingson.io:8086/write?db=[DB_NAME]")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
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()