Jug stands for Just Unified Galloping. Okay, okay, it’s just a play on words coming from a Flask (Python) background.
Jug is my attempt to create a simple small web framework that allows you to turn your (existing) R functions into an API. Having the wonderful
httpuv package at my disposal made this very easy for me.
So, how does this work?
Let’s say I have the following function:
say_hello_to<-function(name) paste("Hello", name)
Sometimes you would be in a situation where you want to send a GET request to a server and let a function (let’s say the one above) return it’s result. Thus, I want to expose the above function to allow HTTP GET requests to acces it. Using Jug I could do something like this:
library(jug) jug() %>% gett("/", decorate(say_hello_to)) %>% serve_it()
Serving the jug at http://127.0.0.1:8080
However, when I run this code and post a GET request to the URL, the following happens:
$ curl 127.0.0.1:8080 ERROR: argument "name" is missing, with no default
Obviously, because the function
say_hello_to requires the parameter
name. A second attempt has better results:
$ curl 127.0.0.1:8080/?name=Bart Hello Bart