Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

api with swift

guard let url = URL(string: "url here") else { return }

var request = URLRequest(url: url)
request.httpMethod = "METHOD HERE"
request.httpBody = Data()
URLSession.shared.dataTask(with: request) { data, response, error in
    if let error = error {
        print(error.localizedDescription)
    }
    guard let data = data else {
        return
    }
    if let jsonText = JSONSerialization.jsonObject(with: data) as? NSDictionary {
        print(jsonText)
    }
    
    if let jsonText = JSONSerialization.jsonObject(with: data) as? NSArray {
        print(jsonText)
    }
}
 
PREVIOUS NEXT
Tagged: #api #swift
ADD COMMENT
Topic
Name
1+7 =