Questions tagged [plumber]

plumber is an R package used to create HTTP APIs from R. It uses annotations above your function definitions to define the structure of your API using existing R code.

The plumber R package allows R users to create HTTP APIs from their R code.

  • Official documentation - Includes documentation about the various features and online examples.
  • CRAN - The package is available on CRAN for easier installation.
307 questions
4
votes
2 answers

Using R's Plumber - create GET endpoint to host CSV formatted data rather than JSON

I think this is a good quick demo of R's plumber library in general, but mainly I'm struggling to serve data in a csv format I am working with R's plumber package to host an API endpoint for some sports data of mine. Currently I have some data that…
Canovice
  • 9,012
  • 22
  • 93
  • 211
4
votes
1 answer

How Do I Consume an Array of JSON Objects using Plumber in R

I have been experimenting with Plumber in R recently, and am having success when I pass the following data using a POST request; {"Gender": "F", "State": "AZ"} This allows me to write a function like the following to return the data. #* @post…
MattW
  • 41
  • 2
4
votes
1 answer

does fwrite lock the file for simultaneous reading

I want to use data.table:: fwrite to do rapid-fire storage & retrieval of states in the form of text logs. These are updated through a mobile app that uses plumber API calls into R endpoints. The mobile apps may fire many APIs per second and there…
Lazarus Thurston
  • 1,197
  • 15
  • 33
4
votes
2 answers

R plumber JSON serializer auto_unbox

Following the example on the page http://plumber.trestletech.com/ I wrote myfile.R as #* @post /test test <- function(){ list(speech='aa',source='bb',displayText='cc') } And I ran the plumber code on it to convert int into an…
anonR
  • 849
  • 7
  • 26
4
votes
1 answer

Have an R Plumber API consume JSON on POST

I'm writing and API in R using plumber that ideally will consume the JSON it receives on POST. But I cannot get the endpoint POST example to work that way, so I'm probably missing something obvious. Using the example URL and Curl I can do the…
FvD
  • 3,697
  • 1
  • 35
  • 53
3
votes
1 answer

Endpoint that returns CSV data is returning string with extra/unnecessary quotes around it

We are using R's plumber library to create an API that returns data in CSV format. For some reason, one of the strings returned is being wrapped with quotes, and we cannot figure out how to resolve this. We have the following example code…
Canovice
  • 9,012
  • 22
  • 93
  • 211
3
votes
1 answer

Provide example body for PUT in Swagger for Plumber

Consider the following example of a PUT request, using Plumber (R API): example_body <- list( a=1, b=2, c=3 ) #* Example PUT endpoint #* @serializer unboxedJSON list(na = NULL) #* @param body:object #* @put /my_example function(req, body =…
fifthace
  • 506
  • 1
  • 10
  • 33
3
votes
1 answer

Adding arbitrary http headers with defaults in Swagger for R Plumber

I have added Bearer token authorization to my Swagger (created with Plumber), using the solution here. Now I would like to add arbitrary headers that are a part of the request. My plumber deployment is used by a React dashboard, where parsing…
fifthace
  • 506
  • 1
  • 10
  • 33
3
votes
2 answers

Swagger UI does not show up in JupyterLab

I have saved one R script with name MC_APIv1.1-Prod.R in Jupyterlab and when I run the following code in R Console of Jupyterlab : plumber::plumb("MC_APIv1.1-Prod.R")$run(host = "0.0.0.0", port = 5763,swagger = TRUE) It gives the following…
ankit
  • 277
  • 1
  • 4
  • 25
3
votes
1 answer

How to send API response without body using Plumber?

Is it possible to send API response without body using Plumber? Here is what I tried: #* @param msg The message to echo back. #* @get /echo function(msg="", res){ res$body<-NULL } and #* @param msg The message to echo back. #* @get…
user1700890
  • 7,144
  • 18
  • 87
  • 183
3
votes
0 answers

R Plumber Database Connection Best Practice

I have an R Plumber API and it's purpose is to receive webhook data, sanitise the data, and then pass it on to a relational database. Is it considered best practice for the API to maintain a constant state of connection to the DB (something like con…
Davide Lorino
  • 875
  • 1
  • 9
  • 27
3
votes
1 answer

Switch between R Plumber Serializers

#* @get /json #* @serializer unboxedJSON function() { return(iris) } #* @get /csv #* @serializer csv list(type="text/plain; charset=UTF-8") function() { return(iris) } #* @param type csv or json #* @get /data function(type = 'csv') { if…
Canovice
  • 9,012
  • 22
  • 93
  • 211
3
votes
0 answers

R How to post three-dimensional array to plumber API?

I have trained a neural network on an image classification task and now try to build an API with plumber to pass data to the model and get back the predictions. But I am stuck on how to pass a three-dimensional array (the image) to the API. I tried…
needRhelp
  • 2,948
  • 2
  • 24
  • 48
3
votes
0 answers

Plumber API to accept images for API scoring

I am trying to write a plumber function to accept images and score on images and return the scored result. So there are two parts I am trying to figure out. Part 1: writing plumber function and this is all I came up with. #* @post…
Not_Dave
  • 491
  • 2
  • 8
3
votes
1 answer

How to return specific error code in plumber API?

How can we return a specific error code from plumber R API? We would like to return a 400 status code with a message, e.g. "Feature x is missing.". We read the plumber documentation but could not figure this out. If we use stop() a 500 Internal…
needRhelp
  • 2,948
  • 2
  • 24
  • 48
1 2
3
20 21