You could also use three routes
library(plumber)
#* @apiTitle Example Plumber API with Serializer to switch formats using object
#* attributes
handler <- function(n = 10) {
data.frame(value = rnorm(n))
}
#* Return a data frame of random values
#* @param n:int* size of data frame
#* @serializer json
#* @get /random_df/json
handler
#* Return a data frame of random values
#* @param n:int* size of data frame
#* @serializer rds
#* @get /random_df/rds
handler
#* Return a data frame of random values
#* @param n:int* size of data frame
#* @serializer csv
#* @get /random_df/csv
handler
programmatic use
library(plumber)
handler <- function(n = 10) {
data.frame(value = rnorm(n))
}
pr() %>%
pr_get("/random_df/csv", handler, serializer = serializer_csv()) %>%
pr_get("/random_df/json", handler, serializer = serializer_json()) %>%
pr_get("/random_df/rds", handler, serializer = serializer_rds()) %>%
pr_run()