Skip to content

Improve docs regarding shipping APIs in R packages #994

Description

@avhz

I am writing an API and shipping it in an R package, as described briefly here:

https://www.rplumber.io/reference/plumb_api.html

It would be helpful to have a bit more information on how this is done.

In particular, for my case, I am interested in how I would register an exit handler, as described here:

https://www.rplumber.io/articles/execution-model.html#exit-handlers

Since I would call the package's API like:

plumber::plumb_api("pkg", "api") |> plumber::pr_run()

Do I register the exit handler in the API file inside the package ?
Or do I do it when I 'plumb' the package's API, like so:

plumber::plumb_api("pkg", "api") |> 
    plumber::pr_hook("exit", function(){ print("Bye bye!")})
    plumber::pr_run()

What if the exit handler depends on an object defined in the package API ?
e.g.

plumber::plumb_api("pkg", "api") |> 
    plumber::pr_hook("exit", function(){ dbDisconnect(connection) }) ## <- 'connection' does not exist here
    plumber::pr_run()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions