Apito REST API Integration with iOS
The Foundation framework provides a base layer of functionality for apps and frameworks, including data storage and persistence, text processing, date and time calculations, sorting and filtering, and networking. The classes, protocols, and data types defined by Foundation are used throughout the macOS, iOS, watchOS, and tvOS SDKs.
note
Always remember to replace API_SECRET
of the Bearer Token and project-id
of the URL with the correct value from apito console.
Go to this page if you do not know where to find your api secrets and endpoints for your project
import Foundation
let headers = [
"content-type": "application/json",
"authorization": "Bearer API_SECRET"
]
let request = NSMutableURLRequest(url: NSURL(string: "https://api.apito.io/secured/rest/project-id")! 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()