Options
All
  • Public
  • Public/Protected
  • All
Menu

Class UrlTemplate

A class that represents a template for matching and parsing urls. The template describes a relative URL and can only include path and query components. The path can include parameters. Only the path is used for matching (the query is ignored for matching.) The query can describe optional parameters. Duplicate parameter names are not allowed.

Examples

The following are examples of valid templates:

"/blog"

Matches "/blog". No parameters are assigned.

"/blog/{blogId}"

Matches "/blog/1". Assigns parameter blogId the value "1".

"/blog/{blogId}/article/{articleId}"

Matches "/blog/1/article/2". Assigns parameter blogId the value "1" and articleId the value "2".

"/blog/{blogId}/article/{articleId}?page={pageNum}"

Matches "/blog/1/article/2" and "/blog/1/article/2?page=3". Assigns parameter blogId the value "1" and articleId the value "2". If "page" is include in the query then assigns parameter pageNum the value "3".

"/download/{file}.{ext}"

Matches "/download/some-file.jpg". Assigns parameter file the value "some-file" and ext the value "jpg".

Hierarchy

  • UrlTemplate

Index

Constructors

Methods

Constructors

constructor

Methods

match

  • match(candidate: Url): boolean
  • Returns true if the url matches the template.

    Parameters

    • candidate: Url

      The url to check.

    Returns boolean

parse

  • parse(url: Url): Map<string, string>
  • Parses parameter values from the given url and returns a map of parameter name to value.

    Parameters

    • url: Url

      The url to parse.

    Returns Map<string, string>

prefix

  • Returns a new UrlTemplate prefixed with the specified base address.

    Parameters

    • address: Url

      The base address.

    Returns UrlTemplate

Generated using TypeDoc