Skip to content

Instantly share code, notes, and snippets.

@ramnov
Last active September 29, 2017 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramnov/62ecd6ad20e087798f7b6c9ae401dc28 to your computer and use it in GitHub Desktop.
Save ramnov/62ecd6ad20e087798f7b6c9ae401dc28 to your computer and use it in GitHub Desktop.
R code to publish web service and create a csharp client
library(mrsdeploy)
carsModel <- glm(formula = am ~ hp + wt, data = mtcars, family = binomial)
manualTransmission <- function(hp, wt) {
newdata <- data.frame(hp = hp, wt = wt)
predict(carsModel, newdata, type = "response")
}
remoteLogin("http://localhost:12800", username = "admin", password = "password", session = FALSE)
api <- publishService(
"ManualTransmissionService",
code = manualTransmission,
model = carsModel,
inputs = list(hp = "numeric", wt = "numeric"),
outputs = list(answer = "numeric"),
v = "v1.0.0"
)
swagger <- api$swagger()
remoteLogout()
library(httr)
r <- httr::POST("http://generator.swagger.io/api/gen/clients/csharp",
add_headers("Content-Type" = "application/json"),
body = paste("{\"options\": { \"packageName\" : \"ManualTransmissionClient\" } ,",
"\"spec\":", swagger, "}"))
download.file(jsonlite::fromJSON(content(r, "text", encoding="UTF-8"))$link,
destfile="ManualTransmissionClient.zip", mode="wb")
clientPath <- file.path(getwd(), "ManualTransmissionClient")
unzip("ManualTransmissionClient.zip", exdir = clientPath, overwrite = T)
print(paste0("Client Code Location : ", clientPath))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment