0

这是应用程序的代码

# load_libraries ----------------------------

library("RestRserve")

# func_UserId ----------------------------

get_userid <- function(req, res) {
  id = req$get_param_path("id")
  res$set_body(id)
}

# create app --------------------------------

app = Application$new()

# define Routes -----------------------------

### /user/:id main Route
app$add_get(
  path = "/user/{id}",
  FUN = get_userid,
  match = "exact"
)

# Run App -----------------------------------

backend = BackendRserve$new()
backend$start(app, http_port = 9000)

而且我无法从路线中提取 ID。我阅读了文档,但仍然不够清楚。如果您对此有任何答案,请告诉我。

提前致谢

4

1 回答 1

2
library(RestRserve)
app = Application$new()
app$add_get("/user/{id}", function(req, res) {
  str(req$parameters_path)
}, match = "regex")

req = Request$new("/user/100500", method = "GET")
res = app$process_request(req)
#List of 1
# $ id: chr "100500"
于 2020-08-02T16:24:57.530 回答