To make an HTTP GET request in Swift, you can use the URLSession
class provided by the iOS SDK. Here's an example code snippet:
main.swift342 chars12 lines
This code creates a URL
object for the endpoint you want to query, then creates a URLSession
object and uses its dataTask
method to make a GET request to that URL. When the request completes, the code prints the response and response data (if available).
Note that in a real-world scenario, you would want to handle errors and parse the response data in a more robust way than what's shown here.
gistlibby LogSnag