pathern

Types

A Pathern type is the result if there is a match

It contains the input path, the pattern that matched, and the parameters extraced from the path, if any

pub type Pathern {
  Pathern(
    path: String,
    pattern: String,
    params: Dict(String, String),
  )
}

Constructors

  • Pathern(
      path: String,
      pattern: String,
      params: Dict(String, String),
    )

Functions

pub fn match(
  path path: String,
  match_pattern pattern: String,
) -> Result(Pathern, Nil)

Matches the path against the pattern

Returns either a Pathern or an Error(Nil)

Examples

match("/user/jane", "/user/:name")
-> Pathern(path: "/user/jane", pattern: "/user/:name", params: [#("name", "jane")])
match("/user/jane", "/user")
-> Error(Nil)
pub fn match_patterns(
  path path: String,
  match_patterns patterns: List(String),
) -> Result(Pathern, Nil)

Matches the path against the list of patterns

Returns either a Pathern or an Error(Nil)

Examples

match_patterns("/user/jane", ["/user", "/user/:name"])
-> Pathern(path: "/user/jane", pattern: "/user/:name", params: [#("name", "jane")])
match_patterns("/user/jane", ["/user", "/"])
-> Error(Nil)
Search Document