URLMappingsBuilder

public class URLMappingsBuilder

Builder that creates a URLMappings object, containing all the mappings for a single feature.

This is used to implement the URL mappings convention of a Feature, which binds schemes, domains and paths to actions. An instance is passed to a closure so that Features can use a DSL-like syntax to declare their mappings.

The resulting URLMappings object is returned by the build function, using covariant return type inference to select the correct build function provided by the extensions on Feature.

  • Define a new URL route from the specified pattern to the action binding of a Feature.

    Use this to define what URLs will invoke the action, and in which scopes. URL routes support simple wildcards and named path elements that can be extracted into route parameters from which the input for the action will be reconstructed.

    Pattern can be of the form:

    • account/profile/view
    • account/*/view (match anything at the 2nd path component)
    • account/** (match everything after /)
    • account/$(id) — extract the second path component as id for parameters, matching only two-component urls
    • account/$(id)/view — extract the second path component as id for parameters, matching only three-component urls
    • account/junk$(id)here/view — extract the second path component part between junk and here as id for parameters, matching only three-component urls
    • account/junk$(id)here/*/view — combining some of the above
    • */$(id) — any two-component path, with the second part used as id parameter
    • */$(id)/view — any three-component path, with the second part used as id parameter, only matching when followed by /view

    Any trailing query parameters on the URL following the optional ? will be extracted first as route parameters. Any named path parameters in the route pattern will supercede these. You can have as many named parameters as you require.

    • param pattern: A URL matching pattern that will match the path only (ignoring query parameters). A leading / is optional, and implied
    • param actionBinding: The action binding to use when performing the action for the URL
    • param scopes: A set of scopes to which the route applies. You can supply as many as you require. The default is [.appAny, .universalAny]
    • param name: An optional value that if supplied will allow your RouteParametersDecodable action input type to tell which route it is being used with, so that you can e.g. customise the input type’s values based on the incoming URL used. For example you might set an isFromPublicLink = true property on the input if the route name was public-web-profile

    Declaration

    Swift

    public func send<FeatureType, ActionType>(_ pattern: String, to actionBinding: StaticActionBinding<FeatureType, ActionType>, in scopes: Set<RouteScope> = [.appAny, .universalAny], name: String? = nil)
            where ActionType.InputType: RouteParametersDecodable
  • Define a new URL route from the specified pattern to the action binding of a ConditionalFeature.

  • param pattern: The URL pattern to match. A leading / is optional, and implied
  • param conditionalActionBinding: The action binding the URL should perform

  • See

    send for static action bindings.

    Declaration

    Swift

    public func send<FeatureType, ActionType>(_ pattern: String, to conditionalActionBinding: ConditionalActionBinding<FeatureType, ActionType>, in scopes: Set<RouteScope> = [.appAny, .universalAny], name: String? = nil)
            where ActionType.InputType: RouteParametersDecodable