r-如何在RestRserve中从路径中提取参数



这是应用的代码

# 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。我看了文件,但还是不够清楚。如果你对此有任何答案,请告诉我。

提前感谢

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"

相关内容

  • 没有找到相关文章

最新更新