Router function

Creates Router object.

Creates Router object.

Examples

r = RestRserve:::Router$new() r$add_path("/test", "exact", "testid") r$add_path("/area", "partial", "areaid") r$add_path("/template/{variable}", "regex", "templateid") r$match_path("/test") # testid r$match_path("/area/entry") # areaid r$match_path("/template/12345") # templateid attr(r$match_path("/template/12345"), "parameters_path") # variables values

Public fields

  • paths: All added paths as is (with templates placeholders).

Methods

Public methods

Method new()

Creates Router object.

Usage

Router$new()

Method size()

Returns number of paths added before.

Usage

Router$size()

Returns

Number of paths.

Method add_path()

Add path with their id.

Usage

Router$add_path(path, match = c("exact", "partial", "regex"), id)

Arguments

  • path: Path to handle.

  • match: Defines how route will be processed. Allowed values:

      * `exact` - match route as is. Returns 404 if route is not matched.
      * `partial` - match route as prefix. Returns 404 if prefix are not matched.
      * `regex` - match route as template. Returns 404 if template pattern not matched.
    
  • id: Path handler id.

Method match_path()

Find path within paths added before. Returns NULL if path not matched.

Usage

Router$match_path(path, extract_vars = TRUE)

Arguments

  • path: Path endpoint.

  • extract_vars: Extart path parameters (when handler matches regex).

Returns

Handler id.

Method clone()

The objects of this class are cloneable with this method.

Usage

Router$clone(deep = FALSE)

Arguments

  • deep: Whether to make a deep clone.