Skip to content

Commit 260f7aa

Browse files
committed
Add run and stop functions
1 parent c512fce commit 260f7aa

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ export(api_post)
6161
export(api_post_header)
6262
export(api_put)
6363
export(api_put_header)
64+
export(api_run)
6465
export(api_session_cookie)
6566
export(api_statics)
67+
export(api_stop)
6668
export(api_trace)
6769
export(api_trace_header)
6870
export(device_formatter)

R/api_run.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#' Launch the API
2+
#'
3+
#' This function starts the api with the settings it has defined.
4+
#'
5+
#' @param api A plumber2 api object to launch or stop
6+
#' @param block Should the console be blocked while running (alternative is
7+
#' to run in the background). Defaults to `FALSE` in interactive sessions and
8+
#' `TRUE` otherwise.
9+
#' @param showcase Should the default browser open up at the server address.
10+
#' If `TRUE` then a browser opens at the root of the api, unless the api
11+
#' contains OpenAPI documentation in which case it will open at that
12+
#' location. If a string the string is used as a path to add to the root
13+
#' before opening.
14+
#' @param ... Arguments passed on to the `start` handler
15+
#' @param silent Should startup messaging by silenced
16+
#'
17+
#' @return These functions return the `api` object allowing for easy chaining
18+
#' with the pipe, even though they will often be the last part of the chain
19+
#'
20+
#' @export
21+
#'
22+
api_run <- function(
23+
api,
24+
block = !is_interactive(),
25+
showcase = is_interactive(),
26+
...,
27+
silent = FALSE
28+
) {
29+
api$ignite(block = block, showcase = showcase, ..., silent = silent)
30+
invisible(api)
31+
}
32+
#' @rdname api_run
33+
#' @export
34+
api_stop <- function(api) {
35+
api$extinguish()
36+
invisible(api)
37+
}

man/api_run.Rd

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)