Search code examples
rapiplumber

Is there a way to create a plumber API in R with no parameters?


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!")
}

Solution

  • 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!"]