Concept

URLSession is used in iOS to perform network requests.

It allows apps to:

send requests to a server
receive responses
handle data asynchronously

Core flow:

URL → URLSession → URLSessionTask → Response

Core Components

URL

Represents the endpoint:

let url = URL(string: "<https://jsonplaceholder.typicode.com/todos/1>")

URLSession

Manages network requests:

let session = URLSession.shared

This is the default shared session.


URLSessionDataTask

Represents the actual request:

let task = session.dataTask(with: url) { data, response, error in
    // handle response
}