<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLProtocol/canonicalRequest(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLProtocol(cm)canonicalRequestForRequest:"
  },
  "title" : "canonicalRequest(for:)"
}
-->

# canonicalRequest(for:)

Returns a canonical version of the specified request.

```
class func canonicalRequest(for request: URLRequest) -> URLRequest
```

## Parameters

`request`

The request whose canonical version is desired.

## Return Value

The canonical form of `request`.

## Discussion

It is up to each concrete protocol implementation to define what “canonical” means. A protocol should guarantee that the same input request always yields the same canonical form.

Special consideration should be given when implementing this method, because the canonical form of a request is used to lookup objects in the URL cache, a process which performs equality checks between [`URLRequest`](/documentation/Foundation/URLRequest) instances.

This is an abstract method and subclasses must provide an implementation.

---

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)