siegerts / drip

🚰 Watch and automatically restart Plumber APIs during development.
https://rdrip.netlify.app
Apache License 2.0
10 stars 1 forks source link
r rest-api rstats

Overview

drip is an easy-to-use development utility that will monitor your Plumber applications for any changes in your source and automatically restart your server.

This project is under development and subject to change. All feedback and issues are welcome. 🍻

The key features of drip are:

Requirements

drip utilizes Rscript to run the Plumber application process. For that reason, R is required for the CLI to correctly execute.

Download and Install

To install drip, find the appropriate package for your system and download it from the download page. drip is packaged as a zip archive.

After downloading drip, unzip the package. drip runs as a single binary named drip. Make sure that the drip binary is available on the PATH.

Plumber Application Structure

drip requires that the Plumber application structure make use of an entrypoint.R that references a plumber.R app.

# entrypoint.R

plumber::plumb("plumber.R")$run("0.0.0.0", port=8000)
# entrypoint.R

library(plumber)

pr <- plumb("plumber.R")

pr$run("0.0.0.0", port=8000)

Use

Command: drip

Watch the current directory for changes using default option flag parameters.

Usage

Available Commands:

Flags:

Example

# cd into project
$ drip

[project-dir] skipping directory: .Rproj.user
[project-dir] skipping directory: node_modules
[project-dir] plumbing...
[project-dir] running: Rscript /project-dir/entrypoint.r
[project-dir] watching...
Starting server to listen on port 8000

[project-dir] modified file: /project-dir/plumber.R
[project-dir] plumbing...
[project-dir] running: Rscript /project-dir/entrypoint.r
[project-dir] watching...

Starting server to listen on port 8000

Command: watch

Watch and rebuild the source if any changes are made across subdirectories

Usage

Usage: drip watch [flags]

The list of available flags are:

Examples

# cd into project
$ drip watch  --routes

[project-dir] skipping directory: .Rproj.user
[project-dir] skipping directory: node_modules
[project-dir] plumbing...
[project-dir] running: Rscript /project-dir/entrypoint.r
[project-dir] routing...

+--------------+----------------------------+---------------+
| PLUMBER VERB |          ENDPOINT          |    HANDLER    |
+--------------+----------------------------+---------------+
| @get         | /echo                      | function      |
| @get         | /dynamic/<param1>/<param2> | function      |
| @get         | /two                       | function      |
| @get         | /plot                      | function      |
| @post        | /sum                       | function      |
| @get         | /req                       | function      |
| @assets      | ./files/static             | static assets |
+--------------+----------------------------+---------------+

[project-dir] watching...
Starting server to listen on port 8000

Or, display routes with an absolute URI and port.

# cd into project
$ drip watch --routes --showHost --host http://localhost

[project-dir] skipping directory: .Rproj.user
[project-dir] skipping directory: node_modules
[project-dir] plumbing...
[project-dir] running: Rscript /project-dir/entrypoint.r
[project-dir] routing...

+--------------+-------------------------------------------------+---------------+
| PLUMBER VERB |                    ENDPOINT                     |    HANDLER    |
+--------------+-------------------------------------------------+---------------+
| @get         | http://localhost:8000/echo                      | function      |
| @get         | http://localhost:8000/dynamic/<param1>/<param2> | function      |
| @get         | http://localhost:8000/plot                      | function      |
| @post        | http://localhost:8000/sum                       | function      |
| @get         | http://localhost:8000/req                       | function      |
| @assets      | http://localhost:8000/files/static              | static assets |
+--------------+-------------------------------------------------+---------------+

[project-dir] watching...
Starting server to listen on port 8000

Command: routes

A quick way to visualize your application's routing structure without starting the watcher

Usage

Usage: drip routes [flags]

Examples

$ drip routes

Command: completion

Generate bash completion commands for drip

Usage

Usage: drip completion [flags]

Developing and Contribution

If you want to work on drip, you'll first need Go installed on your machine.

For local development, first make sure Go is properly installed and that a GOPATH has been set. You will also need to add $GOPATH/bin to your $PATH.

Next, using Git, clone this repository into \$GOPATH/src/github.com/siegerts/drip.

$ git clone github.com/siegerts/drip
$ go build -o build/drip  github.com/siegerts/drip
$ go install github.com/siegerts/drip