Skip to content

Instantly share code, notes, and snippets.

@timle8n1
Created December 8, 2018 17:21
Show Gist options
  • Save timle8n1/09c7cf4cb9d2c6b3fb45ed904a2493ce to your computer and use it in GitHub Desktop.
Save timle8n1/09c7cf4cb9d2c6b3fb45ed904a2493ce to your computer and use it in GitHub Desktop.
Making a JSON Request on Mac OS
let urlSession = URLSession(configuration: .default)
guard let url = URL(string: "https://reqres.in/api/user") else { return }
let task = urlSession.dataTask(with: url) { data, response, error in
guard let content = data,
let json = try? JSONSerialization.jsonObject(with: content) else { return }
print(json)
}
task.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment