如何从 RestRserve 中的路径中提取参数?
How to extract parameters from path in 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"
这是应用程序的代码
# 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"