Learn R Programming

RestRserve (version 0.2.0.2)

Router: Creates Router

Description

Creates Router object.

Arguments

Format

R6::R6Class object.

Construction

Router$new()

Fields

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

Methods

  • size() -> integer(1) Returns number of paths added before.

  • add_path(path, match = c("exact", "partial", "regex"), id) character(1), character(1), character(1) -> Add path with their id.

  • match_path(path, extract_vars = TRUE) character(1), logical(1) -> character(1) | NULL Find path within paths added before. Returns NULL if path not matched.

Examples

Run this code
# NOT RUN {
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

# }

Run the code above in your browser using DataLab