Concept

A GET request is used to retrieve data from a server.

It does not send a request body and is used when the client only needs to fetch information.


Key Idea

Client → sends GET request → Server → returns data

URLSession with GET

In iOS, GET requests are performed using:

URLSession.shared.dataTask

The request is created using a URL or URLRequest.


Creating a GET Request

var request = URLRequest(url: url)
request.httpMethod = "GET"

Even though GET is the default method, setting it explicitly improves clarity.


Example Flow

URLSession.shared.dataTask(with: request) { data, response, error in
    // handle response
}.resume()

Execution Flow