I am looking to send a csv file to a database as someone posts the file using their VBA
code (VBA
has a 80 character limit for their api calls, so they need to upload a csv to the server for me to parse and check)
To do this, I aim to use plumber
and a POST
request. My knowledge is a bit limited on how to structure the api to do this. Below is a rough example of how I see it happening. Is this even possible to do with plumber
?
# api_main.R
library(plumber)
#* @awesomeAPI Simple API to upload csv
#* Return status on received csv
#* @param req
#* @post /upload
function(req) {
df <- read.csv(req$body)
if(all(c("A", "B", "C", "D") %in% names(df))){
return(data.frame(msg = "Not all columns available", status = 418))
} else {
# upload data to DB here
return(data.frame(msg = "OK", status = 200))
}
}
Start the service:
plumber::plumb("api_main.R")$run(port = 5762)