MatchedURL

public class MatchedURL

Represents a URL that has been matched to a registered route.

Provides parameter mapping shortcuts.

Note

For use when handling routing parameters.

Usage:

// Path components
let name: String = try $0.path("name")
let pageId: Int = try $0.path("id")

// Query string parameters
let all: [String: String] = $0.queryParameters
let offset: String? = $0.query("offset")
let page = $0.query("page") ?? 0

// URL Host/Scheme
let host: String? = $0.host
let scheme: String? = $0.scheme
  • Associated URL

    Declaration

    Swift

    public let rawURL: URL
  • Query string parameter shortcuts

    Declaration

    Swift

    public lazy var queryParameters: [String : String] { get set }
  • Get the scheme (e.g. “https”)

    Declaration

    Swift

    public lazy var scheme: String? { get set }
  • Get the host (e.g. “example.com”)

    Declaration

    Swift

    public lazy var host: String? { get set }

Methods

  • Retrieve a path parameter as a String

    Declaration

    Swift

    public func path(_ name: String) throws -> String
  • Retrieve a path parameter as an Int

    Declaration

    Swift

    public func path(_ name: String) throws -> Int
  • Retrieve a query string parameter as a String

    Declaration

    Swift

    public func query(_ name: String) -> String?
  • Retrieve a query string parameter as an Int

    Declaration

    Swift

    public func query(_ name: String) -> Int?