Last active
September 29, 2017 19:50
-
-
Save ramnov/62ecd6ad20e087798f7b6c9ae401dc28 to your computer and use it in GitHub Desktop.
R code to publish web service and create a csharp client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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