Can we use the API directly with SwiftUI? #220
-
TIA |
Beta Was this translation helpful? Give feedback.
Answered by
lukeocodes
Jun 19, 2023
Replies: 1 comment
-
You can integrate directly using Swift. Here is some auto-generated code from the examples in our docs: import Foundation
let headers = [
"content-type": "application/json",
"Authorization": "Token YOUR_DEEPGRAM_API_KEY"
]
let parameters = ["url": "https://dpgr.am/spacewalk.wav"] as [String : Any]
let postData = JSONSerialization.data(withJSONObject: parameters, options: [])
let request = NSMutableURLRequest(url: NSURL(string: "https://api.deepgram.com/v1/listen")! 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 as Any)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume() Let me know if this works, I've not tried it in Swift before! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jpvajda
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can integrate directly using Swift. Here is some auto-generated code from the examples in our docs: