4

Im looking to separate out my complex API structure so that I have the following structure. I am wondering. Is there a way to mount all files under the users/ folder to the same ./api/v1/users route? And the same for projects/ ? One key point of consideration is the fact that I will have dynamic routes defined within these files too (e.g. ./projects/<project_id>)

In shiny, to accomplish something like this Id use source('file.R', local=TRUE) but Plumber doesn't work in the same way. The reason I am structuring it this way is to reduce complexity during development (as opposed to adding multiple verbs to the same endpoint).

+-- v1/
|+-- users/
|+----- GET.R
|+----- POST.R
|+-- projects/
|+----- GET.R
|+----- POST.R

Ive tested mounting but unfortunately cannot mount multiple files from each folder to the same route name. See the example code

v2 <- plumber::Plumber$new("api/v1/projects/GET.R")
root$mount(paste0(ROOT_URI,"/v1"), v2)
v1 <- plumber::Plumber$new("api/v1/projects/POST.R")
root$mount(paste0(ROOT_URI,"/v1"), v1)

(within the GET.R and POST.R files are each one function named "projects" that handle one of two verbs)

BejanSadeghian
  • 609
  • 1
  • 6
  • 10

1 Answers1

0

The answer is sort of. Using the 'here' package allows you to import functions defined within files relative to your plumber file. Then in your plumber file you can fill in your decorator and place your function after it.

BejanSadeghian
  • 609
  • 1
  • 6
  • 10