During the life cycle of a plumber API various events will be fired, either
automatically or manually. See the article on events in fiery
for a full overview. api_on()
allows you to add handlers that are called
when specific events fire. api_off()
can be used to remove the handler if
necessary
Using annotation
Event handler setup doesn't have a dedicated annotation tag, but you can set
it up in a @plumber
block
Examples
# Add a small console log to show the api is alive
papi <- api() |>
api_on("cycle-end", function(server) {
server$log("message", "tick-tock")
}, id = "lifesign")
# Remove it again
papi |>
api_off("lifesign")
#> ── A plumber server ────────────────────────────────────────────────────────────
#> Serving on http://127.0.0.1:8080
#> Currently not running