rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.39k stars 256 forks source link

entrypoint.R documentation / examples #467

Open aronatkins opened 5 years ago

aronatkins commented 5 years ago

The entrypoint.R file exists to let developers construct their own custom router. The only documentation I could find is this reference in the help for the dir argument to plumber::plumb:

The directory containing the plumber.R file to parse as the plumber router definition. Alternatively, if an entrypoint.R file is found, it will take precedence and be responsible for returning a runnable Plumber router.

This help is true, but most developers won't know what it means to return a runnable Plumber router.

There is one small example but its code is presented without explaining documentation: https://github.com/trestletech/plumber/tree/master/inst/examples/12-entrypoint

schloerke commented 5 years ago

cc @blairj09

stufield commented 5 years ago

Agree. I am also having trouble customizing the swagger interface in the entrypoint.R file.

Sorry if this is the wrong place to post this, but I think it may be so obvious I'm missing something. I am trying to specify the expected JSON format of incoming requests. For example (in entrypoint.R) :

    schema = list(
            title = "predict values",
            required = c("cyl", "hp"),
            properties = list(
              cyl = list(type = "integer"),       # is there a way to specify a default value here??
              hp = list(type = "number")
              )
            )

results in Swagger like this:

{
  "cyl": 0,
  "hp": 0
}

Which shows the expected format for 1 row of data, however our input is a data frame of test values needed to generate predicted values, so I would like to specify an array, yet it is not obvious to me how to accomplish this. Here is what I am looking for (note [ and ]):

[
  {
    "cyl": 0,
    "hp": 0
  },
  {
    "cyl": 0,
    "hp": 0
  }
]

Showing (for example) 2 rows of expected format. It seems this should be relatively simple, though extensive Googling has come up empty. Thanks in advance!

schloerke commented 5 years ago

@stufield Can you open a new issue with your comment? I don't understand how the schema is connected to swagger for you. (Will need more in your example to understand).

(Will hide these two comments in this issue once you've posted a new one.)

stufield commented 5 years ago

Sure no problem. I was going to do just that but saw this issue and they seemed similar enough. I will also try to clarify (reading now I see how you may be unclear) :(

schloerke commented 5 years ago

Larger example by @aronatkins https://github.com/rstudio/plumber/issues/481#issuecomment-525752560

JosiahParry commented 3 months ago

Came here to note that there is no documentation on the entrypoint.R it is only referenced in the NEWS.md and in the Process a Plumber API docs.

"Alternatively, if an entrypoint.R file is found, it will take precedence and be responsible for returning a runnable router."

it is unclear to me what the entrypoint.R is and how it should be used