How to customize input param in R plumber api

462 views Asked by At

I have a API where I want customize input param as per user input(z)

#* @param a Enter your Website
#* @param z Enter No of competitor you want to check
#* @param b Enter First URL
#* @param c Enter Second URL
#* @param d Enter Third URL
#* @param e Enter Fourth URL
#* @param f Enter Fifth URL
#* @param g Enter Sixth URL
#* @param h Enter Seventh URL
#* @param i Enter Eighth URL
#* @param j Enter Ninth URL
#* @param k Enter Tenth URL
#* @param v The focused keyword

function(a,z,v) {}

is this a right way? can anyone suggest?

1

There are 1 answers

3
Bruno Tremblay On BEST ANSWER

Using plumber 1.0.0, make them an array instead?

library(plumber)

#* @param a Enter your Website
#* @param b:[chr] Enter URLs
#* @param v The focused keyword
#* @get /something
function(a,b,v) {
  if (length(b) > 10) {
    stop("this api can handle at most 10 urls")
  }
  length(b)
}

#* @plumber
function(pr) {
  pr_set_api_spec(pr, function(spec) {
    spec$paths$`/something`$get$parameters[[2]]$schema$maxItems = 10
    spec
  })
  pr_set_debug(pr, TRUE)
}