Skip to content

Instantly share code, notes, and snippets.

@JosiahParry
Created January 18, 2025 19:53
Show Gist options
  • Save JosiahParry/539f343bc8b17ed1396fcee5ae5cc346 to your computer and use it in GitHub Desktop.
Save JosiahParry/539f343bc8b17ed1396fcee5ae5cc346 to your computer and use it in GitHub Desktop.
API done 2 wayys ambiorix vs plumber
app <- ambiorix::Ambiorix$new()
app$post("/process", function(req, res) {
body <- yyjsonr::read_json_raw(req$rook.input$read())
msg <- sprintf(
"Hello, %s! Your age is %i, and your email is %s.",
body[["name"]], body[["age"]], body[["email"]]
)
res$json(list(message = msg, status = "success"))
})
app$start()
library(plumber)
pr() |>
pr_post("/process", function(req, res) {
msg <- sprintf(
"Hello, %s! Your age is %i, and your email is %s.",
req$body[["name"]], req$body[["age"]], req$body[["email"]]
)
list(message = msg, status = "success")
}) |>
pr_run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment