Hi everyone,
I have an API that I am developping on my computer then deploying on the RStudio connect server.
I have the following code to make sure it works when deployed on my computer.
library(testthat)
library(httr)
root_path <- "http://localhost"api1 <- callr::r_bg(
function() {
pr <- plumber::plumb(here::here("plumber.R"))
pr$run(port = 8000)
}
)Sys.sleep(5)
test_that("API is alive", {
expect_true(api1$is_alive())
})test_that("echo endpoint works", {
Send API request
r <- httr::GET(root_path, port = 8000, path = "echo", query = list(msg = "Hello World"))
Check response
expect_equal(r$status_code, 200)
expect_equal(httr::content(r, encoding = "UTF-8"), list(msg = list("The message is: 'Hello World'")))
})
I would like to be able to run a similar test on the API when deployed on my RStudio connect server, but I'm not sure how to call it since I would need to pass it my username/password.
For the sake of argument let's say my endpoint on the server is located at
https://rstudiotest.mycompany.com/myapi/echo