---
title: URLRequest
framework: foundation
role: symbol
role_heading: Structure
path: foundation/urlrequest
---

# URLRequest

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

## Declaration

```swift
struct URLRequest
```

## Mentioned in

Uploading data to a website Accessing cached data Downloading files from websites Downloading files in the background Processing URL session data task results with Combine Uploading streams of data

## Overview

Overview URLRequest encapsulates two essential properties of a load request: the URL to load and the policies used to load it. In addition, for HTTP and HTTPS requests, URLRequest includes the HTTP method (GET, POST, and so on) and the HTTP headers. URLRequest only represents information about the request. Use other classes, such as URLSession, to send the request to a server. See Fetching website data into memory and Uploading data to a website for an introduction to these techniques. When writing Swift code, favor this structure over the NSURLRequest and NSMutableURLRequest classes. Certain header fields are reserved; see Reserved HTTP headers.

## Topics

### Creating a request

- [init(url:cachePolicy:timeoutInterval:)](foundation/urlrequest/init(url:cachepolicy:timeoutinterval:).md)

### Working with a cache policy

- [cachePolicy](foundation/urlrequest/cachepolicy-swift.property.md)
- [URLRequest.CachePolicy](foundation/urlrequest/cachepolicy-swift.typealias.md)
- [NSURLRequest.CachePolicy](foundation/nsurlrequest/cachepolicy-swift.enum.md)

### Accessing request components

- [httpMethod](foundation/urlrequest/httpmethod.md)
- [url](foundation/urlrequest/url.md)
- [httpBody](foundation/urlrequest/httpbody.md)
- [httpBodyStream](foundation/urlrequest/httpbodystream.md)
- [mainDocumentURL](foundation/urlrequest/maindocumenturl.md)

### Accessing header fields

- [allHTTPHeaderFields](foundation/urlrequest/allhttpheaderfields.md)
- [addValue(_:forHTTPHeaderField:)](foundation/urlrequest/addvalue(_:forhttpheaderfield:).md)
- [setValue(_:forHTTPHeaderField:)](foundation/urlrequest/setvalue(_:forhttpheaderfield:).md)
- [value(forHTTPHeaderField:)](foundation/urlrequest/value(forhttpheaderfield:).md)

### Controlling request behavior

- [timeoutInterval](foundation/urlrequest/timeoutinterval.md)
- [httpShouldHandleCookies](foundation/urlrequest/httpshouldhandlecookies.md)
- [httpShouldUsePipelining](foundation/urlrequest/httpshouldusepipelining.md)
- [allowsCellularAccess](foundation/urlrequest/allowscellularaccess.md)
- [allowsPersistentDNS](foundation/urlrequest/allowspersistentdns.md)
- [assumesHTTP3Capable](foundation/urlrequest/assumeshttp3capable.md)
- [cookiePartitionIdentifier](foundation/urlrequest/cookiepartitionidentifier.md)
- [requiresDNSSECValidation](foundation/urlrequest/requiresdnssecvalidation.md)

### Supporting limited modes

- [allowsConstrainedNetworkAccess](foundation/urlrequest/allowsconstrainednetworkaccess.md)
- [allowsExpensiveNetworkAccess](foundation/urlrequest/allowsexpensivenetworkaccess.md)

### Accessing the service type

- [networkServiceType](foundation/urlrequest/networkservicetype-swift.property.md)
- [URLRequest.NetworkServiceType](foundation/urlrequest/networkservicetype-swift.typealias.md)
- [NSURLRequest.NetworkServiceType](foundation/nsurlrequest/networkservicetype-swift.enum.md)

### Indicating the source of the request

- [attribution](foundation/urlrequest/attribution-swift.property.md)
- [URLRequest.Attribution](foundation/urlrequest/attribution-swift.typealias.md)

### Using reference types

- [NSURLRequest](foundation/nsurlrequest.md)
- [NSMutableURLRequest](foundation/nsmutableurlrequest.md)
- [MutableURLRequest](foundation/mutableurlrequest.md)

### Instance Properties

- [allowsUltraConstrainedNetworkAccess](foundation/urlrequest/allowsultraconstrainednetworkaccess.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [ReferenceConvertible](foundation/referenceconvertible.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Requests and responses

- [NSURLRequest](foundation/nsurlrequest.md)
- [NSMutableURLRequest](foundation/nsmutableurlrequest.md)
- [URLResponse](foundation/urlresponse.md)
- [HTTPURLResponse](foundation/httpurlresponse.md)
