When defining API endpoints using {plumber} as, for instance, in the example of Quickstart vignette of plumber itself ref
#* Plot out data from the iris dataset
#* @param spec If provided, filter the data to only this species (e.g. 'setosa')
#* @get /plot
#* @serializer png
function(spec){
myData <- iris
title <- "All Species"
# Filter if the species was specified
if (!missing(spec)){
title <- paste0("Only the '", spec, "' Species")
myData <- subset(iris, Species == spec)
}
plot(myData$Sepal.Length, myData$Petal.Length,
main=title, xlab="Sepal Length", ylab="Petal Length")
}
parameter spec
becomes "required". It means you are forced to enter a value for it (as you can check in the swagger obtained by launching "Run API" in RStudio). Therefore, you cannot get the plot for the whole dataset when no value is passed for parameter spec
.
There are ways to fix it, for instance by setting a default to NULL and changing the endpoint behavior if spec=NULL
. Nevertheless, this is not the behavior expected according to the vignette mentioned above.
On the other hand, It looks like using progammatic API definition you can set required = FALSE
for the parameter list.
Please, how can you change the default behavior of Plumber to use required = FALSE
for spec
parameter?