<!--
{
  "documentType" : "article",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/url-loading-system",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "URL Loading System"
}
-->

# URL Loading System

Interact with URLs and communicate with servers using standard Internet protocols.

## Discussion

The URL Loading System provides access to resources identified by URLs, using standard protocols like `https` or custom protocols you create. Loading is performed asynchronously, so your app can remain responsive and handle incoming data or errors as they arrive.

You use a [`URLSession`](/documentation/Foundation/URLSession) instance to create one or more [`URLSessionTask`](/documentation/Foundation/URLSessionTask) instances, which can fetch and return data to your app, download files, or upload data and files to remote locations. To configure a session, you use a [`URLSessionConfiguration`](/documentation/Foundation/URLSessionConfiguration) object, which controls behavior like how to use caches and cookies, or whether to allow connections on a cellular network.

You can use one session repeatedly to create tasks. For example, a web browser might have separate sessions for regular and private browsing use, where the private session doesn’t cache its data. [Figure 1](/documentation/foundation/url_loading_system#2927983) shows how two sessions with these configurations can then create multiple tasks.

![Figure showing two scenarios, default browsing and private browsing, each with a URL Session creating multiple URL Session Tasks. In the default browsing case, the URL Session contains a default configuration. In the private browsing case, it contains an ephemeral configuration.](images/com.apple.foundation/media-2927983@2x.png)

Each session is associated with a delegate to receive periodic updates (or errors). The default delegate calls a completion handler block that you provide; if you choose to provide your own custom delegate, this block is not called.

You can configure a session to run in the background, so that while the app is suspended, the system can download data on its behalf and wake up the app to deliver the results.

## Topics

### Essentials

Configure and create sessions, then use them to create tasks that interact with URLs.

[Fetching website data into memory](/documentation/Foundation/fetching-website-data-into-memory)

Receive data directly into memory by creating a data task from a URL session.

[Analyzing HTTP traffic with Instruments](/documentation/Foundation/analyzing-http-traffic-with-instruments)

Measure HTTP-based network performance and usage of your apps.

[`URLSession`](/documentation/Foundation/URLSession)

An object that coordinates a group of related, network data transfer tasks.

[`URLSessionTask`](/documentation/Foundation/URLSessionTask)

A task, like downloading a specific resource, performed in a URL session.

### Requests and responses

[`URLRequest`](/documentation/Foundation/URLRequest)

A URL load request that is independent of protocol or URL scheme.

[`NSURLRequest`](/documentation/Foundation/NSURLRequest)

A URL load request that is independent of protocol or URL scheme.

[`NSMutableURLRequest`](/documentation/Foundation/NSMutableURLRequest)

A mutable URL load request that is independent of protocol or URL scheme.

[`URLResponse`](/documentation/Foundation/URLResponse)

The metadata associated with the response to a URL load request, independent of protocol and URL scheme.

[`HTTPURLResponse`](/documentation/Foundation/HTTPURLResponse)

The metadata associated with the response to an HTTP protocol URL load request.

### Uploading

[Building a resumable upload server with SwiftNIO](/documentation/Foundation/building-a-resumable-upload-server-with-swiftnio)

Support HTTP resumable upload protocol in SwiftNIO by translating resumable uploads to regular uploads.

[Uploading data to a website](/documentation/Foundation/uploading-data-to-a-website)

Post data from your app to servers.

[Uploading streams of data](/documentation/Foundation/uploading-streams-of-data)

Send a stream of data to a server.

[Pausing and resuming uploads](/documentation/Foundation/pausing-and-resuming-uploads)

Pause and resume an upload without starting over, even when the connection is interrupted.

### Downloading

[Downloading files from websites](/documentation/Foundation/downloading-files-from-websites)

Download files directly to the filesystem.

[Pausing and resuming downloads](/documentation/Foundation/pausing-and-resuming-downloads)

Allow the user to resume a download without starting over.

[Downloading files in the background](/documentation/Foundation/downloading-files-in-the-background)

Create tasks that download files while your app is inactive.

### Cache behavior

[Accessing cached data](/documentation/Foundation/accessing-cached-data)

Control how URL requests make use of previously cached data.

[`CachedURLResponse`](/documentation/Foundation/CachedURLResponse)

A cached response to a URL request.

[`URLCache`](/documentation/Foundation/URLCache)

An object that maps URL requests to cached response objects.

### Authentication and credentials

[Handling an authentication challenge](/documentation/Foundation/handling-an-authentication-challenge)

Respond appropriately when a server demands authentication for a URL request.

[`URLAuthenticationChallenge`](/documentation/Foundation/URLAuthenticationChallenge)

A challenge from a server requiring authentication from the client.

[`URLCredential`](/documentation/Foundation/URLCredential)

`A`n authentication credential consisting of information specific to the type of credential and the type of persistent storage to use, if any.

[`URLCredentialStorage`](/documentation/Foundation/URLCredentialStorage)

The manager of a shared credentials cache.

[`URLProtectionSpace`](/documentation/Foundation/URLProtectionSpace)

A server or an area on a server, commonly referred to as a realm, that requires authentication.

### Network activity attribution

  <doc://com.apple.documentation/documentation/Network/inspecting-app-activity-data>

  <doc://com.apple.documentation/documentation/Network/indicating-the-source-of-network-activity>

### Cookies

[`HTTPCookie`](/documentation/Foundation/HTTPCookie)

A representation of an HTTP cookie.

[`HTTPCookieStorage`](/documentation/Foundation/HTTPCookieStorage)

A container that manages the storage of cookies.

### Errors

[`URLError`](/documentation/Foundation/URLError)

Error codes returned by URL loading APIs.

[URL Loading System error info keys](/documentation/Foundation/url-loading-system-error-info-keys)

Recognize these keys from the user info dictionary of error objects produced by URL Loading APIs.

### Legacy

[Legacy URL Loading Systems](/documentation/Foundation/legacy-url-loading-systems)

Migrate your code away from using these legacy objects.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)