有没有一种方法可以在没有参数的R中创建水管工API?

发布于 2025-02-07 12:04:20 字数 320 浏览 2 评论 0原文

当用户ping ping时,我正在尝试仅返回一个字符串或数据框架。我正在使用水管工来创建此API。不幸的是,当我尝试执行此操作时,我会继续遇到404错误。这可以在水管工中吗?

library(plumber)

#* Test plumber of API with no parameters
#* @response default array with corresponding responses
#* @serializer unboxedJSON
#* @post /Test


function(){
 
  return("Hello World!")
}

I'm trying to return just a string or a data frame as soon as the API is pinged by the user. I'm using plumber to create this API. Unfortunately, I keep on getting a 404 error when I try to do this. Is this possible in plumber?

library(plumber)

#* Test plumber of API with no parameters
#* @response default array with corresponding responses
#* @serializer unboxedJSON
#* @post /Test


function(){
 
  return("Hello World!")
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筱果果 2025-02-14 12:04:20

它对我有用。将您的脚本保存为Plumber_test.r,然后打开R会话并输入

> library(plumber)
> reply_service <- pr('plumber_test.R')
> pr_run(reply_service, port=9494, host='127.0.0.1')

另一个终端尝试

$ curl -X POST http://127.0.0.1:9494/Test

,您应该返回[“ Hello World!”]

It works for me. Save your script as plumber_test.R, then open an R session and type

> library(plumber)
> reply_service <- pr('plumber_test.R')
> pr_run(reply_service, port=9494, host='127.0.0.1')

In another terminal try

$ curl -X POST http://127.0.0.1:9494/Test

And you should get back ["Hello World!"]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文