I am not sure whether I am on the right track with my question, so here is what I am trying to do: I would like to implement something like the data api endpoints, e.g.:
hadley.ocpu.io/ggplot2/data/msleep/csv
and hope to be able to use all the great json, csv stuff that's already provided by opencpu
. Yet I would not like to call a static file stored somewhere within a package but rather call a function that queries a database and returns an R object that the json / csv functionality of openCPU
can process.
I read this post and the corresponding documentation. It teaches how to make RPC calls using JS. This is great, but requires me to build a minimal JS app. However, I would like to share or embed a single link that does nothing but returning csv or json.
I tried to create a package that contains a function like this:
hello <- function() {
# mtcars will be replaced by
# whatever the db returns
mtcars
}
But http://localhost:8100/ocpu/library/resttest/R/hello/json
obviously just returns a json of the function itself. Did I miss something simple / basic or is it more difficult to create such a custom endpoint?
Though it would be nice to be able to pass some arguments using standard GET, I could very well live with parameter less functions and summarize them in a package that contains one function for every dataset.
EDIT: Actually this part of the documentation (at the very bottom) about the 'common special case' is very close. All I would like to have is GET request, so I could just have a link instead of js client / call. https://www.opencpu.org/api.html#api-arguments