rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.39k stars 256 forks source link

How to return a 40* (status) from a GET? #302

Closed AndreGuerra123 closed 6 years ago

AndreGuerra123 commented 6 years ago
assert<- function(res,val,msg){
  if(!val){
    res$status <- 404
    res$msg <- msg
  }
}

#* Get list of available datasetsfor a user
#* @param userid userid
#* @get /datasets/available
function(userid){
  assert()
  MORE CODE.....
  return()
}

How do I get to the result (res) parameter from within a get function in plumber? I'm used to other API in flask and js which usually carry the req,res,(next) parameters at the top of the function. But here the request params are passed directly to the function.

schloerke commented 6 years ago

@AndreGuerra123 Check out https://www.rplumber.io/docs/programmatic-usage.html#defining-endpoints for a more programmatic approach to defining the router