0

I am trying to provide a R function as a web service for which I am using https://blogs.msdn.microsoft.com/mlserver/2018/07/26/dockerizing-r-and-python-web-services/ as a reference.

I changed my function accordingly so that it should accept a dataframe. I want to consume the web service through curl. How do I pass a dataframe to publishService function through curl?

I tried send the dataframe as a JSON so that curl POST should accept it as a string, but it isn't accepting.

library(mrsdeploy)
library(jsonlite)
manualTransmission <- function(hp, wt) { 
     hp <- jsonlite::fromJSON(hp)
     wt <- jsonlite::fromJSON(wt)
     c(hp[1,1],wt[1,1]) 
}
remoteLogin("http://localhost:12800", username = "admin", password = 
"Microsoft@2018", session = FALSE)
api <- publishService("ManualTransmissionService", code = 
manualTransmission, inputs = list(hp = "character", wt = "character"), 
outputs = list(answer = "vector"), v = "1.0.0") 

The command:

curl --header "Content-Type: application/json" --header "Authorization: Bearer <accesstoken>" --request POST --data "{\"hp\": \"[{\"hp_col\": 5}]\",\"wt\": \"[{\"wt_col\": 5}]\"}" http://localhost:12800/api/ManualTransmissionService/1.0.0 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • what error do you see? – Niels Berglund Jan 24 '19 at 04:02
  • > Content-Length: 49 > * upload completely sent off: 49 out of 49 bytes < HTTP/1.1 400 Bad Request < Date: Thu, 24 Jan 2019 05:55:20 GMT < Content-Type: application/json < Server: Kestrel < Content-Length: 158 < X-Content-Type-Options: nosniff < x-ms-request-id: 9ac57d0c-c852-46ab-9642-d3bc853f38b8 < {"Link":"https://go.microsoft.com/fwlink/?linkid=830136","Message":"Number of parameter mismatch. Expected: 2, Actual: 0","ExceptionType":"ArgumentException"}* Connection #0 to host localhost left intact – Vedapragna Reddy Jan 24 '19 at 05:56

0 Answers0