12.1 · Sessions, configurations, tasks, delegates and background transfers
URLSession is the foundation under every Apple networking stack. Most surprises come from three facts: configuration is fixed at creation, an HTTP error is not a Swift error, and a session retains its delegate.
Mental model. A session is a policy object (timeouts, caches, cookies, connectivity). Tasks are the individual requests that run under it.
Sessions and tasks
Configurations, defaults and what a request returns.
- What do the URLSession configurations control, and how do default, ephemeral and background sessions differ?
A URLSession is created from a URLSessionConfiguration that fixes its behaviour: timeouts, cache and cookie storage, credential storage, cellular and… - How do you make a request with URLSession, and why is a 404 not an error?
The modern call is async: let (data, response) = try await session.data(for: request) (also data(from:), upload(for:from:) and download(for:), which writes to…
More in Networking
- 12.2 · HTTP versions, TLS, App Transport Security and certificate pinning
- 12.3 · Pagination, caching and conditional requests, and authentication refresh
- 12.4 · WebSockets, multipart and large transfers, and network path monitoring
- 12.5 · Retries, backoff, idempotency and cancellation
- 12.6 · REST, GraphQL and gRPC, and building a client platform
- 12.7 · Image loading pipelines: download, decode, downsample, cache
- 12.8 · Building URLs, reading headers, classifying errors and timeouts
- 12.9 · Single-flight token refresh, streaming lines, multipart bodies and request signing
- 12.10 · Network.framework, background sessions, delegates versus async, diagnosing and measuring