Skip to content

URLTemplate

mattpolzin edited this page Sep 28, 2020 · 6 revisions

URLTemplate

A URL that may contain variable placeholders.

public struct URLTemplate: Hashable, RawRepresentable

Variable placeholders are enclosed with curly braces. They can exist anywhere within the URL.

Examples:

// no variables
"https://website.com/a/path?query=value"

// scheme
"{scheme}://website.com/a/path?query=value"

// host
"https://{host}/a/path?query=value"

// just the domain
"https://{domain}.com/a/path?query=value"

// the whole url
"{server}"

// etc.

Inheritance

Decodable, Encodable, Hashable, RawRepresentable

Initializers

init?(rawValue:)

Create a URLTemplate from the string if possible.

public init?(rawValue: String)

init(url:)

public init(url: URL)

init(from:)

public init(from decoder: Decoder) throws

Properties

rawValue

The string value of the URL.

let rawValue: String

This is equivalent to the absoluteString (i.e. the entire URL).

absoluteString

The entire URL as a string.

var absoluteString: String

This is equivalent to the absoluteString provided by the Foundation URL type except that a URLTemplate's absoluteString can contain variable placeholders.

url

Get a URL from this templated URL if it is a valid URL already.

var url: URL?

Templated URLS with variables in them will not be valid URLs and are therefore guaranteed to return nil.

Methods

encode(to:)

public func encode(to encoder: Encoder) throws
Types
Protocols
Global Functions
Extensions
Clone this wiki locally