Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove /api prefix #20

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/router.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build_routes <- function(cookie_key = plumber::random_cookie_key(),
pr$handle(get_version())
# porcelain doesn't support multipart form content yet; for now wire this
# endpoint up using plumber arguments instead
pr$handle("POST", "/api/dataset/", target_post_dataset,
pr$handle("POST", "/dataset/", target_post_dataset,
serializer = plumber::serializer_unboxed_json(null = "null"))
pr$handle(options_dataset())
pr$handle(delete_dataset())
Expand Down
20 changes: 10 additions & 10 deletions R/routes.R
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
get_root <- function() {
porcelain::porcelain_endpoint$new(
"GET",
"/api/",
"/",
target_get_root,
returning = porcelain::porcelain_returning_json())
}

get_version <- function() {
porcelain::porcelain_endpoint$new(
"GET",
"/api/version/",
"/version/",
target_get_version,
returning = porcelain::porcelain_returning_json("Version"))
}

get_dataset <- function() {
porcelain::porcelain_endpoint$new(
"GET", "/api/dataset/<name>/",
"GET", "/dataset/<name>/",
target_get_dataset,
returning = porcelain::porcelain_returning_json("DatasetMetadata"))
}

delete_dataset <- function() {
porcelain::porcelain_endpoint$new(
"DELETE", "/api/dataset/<name>/",
"DELETE", "/dataset/<name>/",
target_delete_dataset,
returning = porcelain::porcelain_returning_json())
}

options_dataset <- function() {
porcelain::porcelain_endpoint$new(
"OPTIONS", "/api/dataset/<name>/",
"OPTIONS", "/dataset/<name>/",
function(name) "OK",
returning = porcelain::porcelain_returning_json())
}

get_datasets <- function() {
porcelain::porcelain_endpoint$new(
"GET",
"/api/datasets/",
"/datasets/",
target_get_datasets,
returning = porcelain::porcelain_returning_json("DatasetNames"))
}

get_trace <- function() {
porcelain::porcelain_endpoint$new(
"GET",
"/api/dataset/<name>/trace/<biomarker>/",
"/dataset/<name>/trace/<biomarker>/",
target_get_trace,
porcelain::porcelain_input_query(disaggregate = "string",
filter = "string",
Expand All @@ -60,7 +60,7 @@ get_trace <- function() {
get_individual <- function() {
porcelain::porcelain_endpoint$new(
"GET",
"/api/dataset/<name>/individual/<pidcol>/",
"/dataset/<name>/individual/<pidcol>/",
target_get_individual,
porcelain::porcelain_input_query(scale = "string",
color = "string",
Expand All @@ -72,14 +72,14 @@ get_individual <- function() {

options_session <- function() {
porcelain::porcelain_endpoint$new(
"OPTIONS", "/api/session/",
"OPTIONS", "/session/",
function() "OK",
returning = porcelain::porcelain_returning_json())
}

delete_session <- function() {
porcelain::porcelain_endpoint$new(
"DELETE", "/api/session/",
"DELETE", "/session/",
target_delete_session,
returning = porcelain::porcelain_returning_json())
}
2 changes: 1 addition & 1 deletion docker/smoke-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ wait_for()
echo "waiting up to $TIMEOUT seconds for app"
start_ts=$(date +%s)
for i in $(seq $TIMEOUT); do
result="$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:8888/api/ 2>/dev/null)"
result="$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:8888/ 2>/dev/null)"
if [[ $result -eq "200" ]]; then
end_ts=$(date +%s)
echo "App available after $((end_ts - start_ts)) seconds"
Expand Down
3 changes: 1 addition & 2 deletions inst/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ info:
name: GPL (>= 3)
url: https://www.gnu.org/licenses/gpl-3.0.en.html
servers:
- url: https://seroviz.seroanalytics.org/api
- url: https://seroviz.seroanalytics.org
- url: http://localhost:8888
basePath: "/api"
paths:
/:
get:
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ make_req <- function(verb = "GET",
...) {
req <- as.environment(list(...))
req$REQUEST_METHOD <- toupper(verb)
req$PATH_INFO <- paste0("/api", path)
req$PATH_INFO <- path
req$QUERY_STRING <- qs
if (is.character(body)) {
body <- charToRaw(body)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-router.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("GET /", {
expect_equal(res_endpoint$data, res)

router <- build_routes()
res_api <- router$request("GET", "/api/")
res_api <- router$request("GET", "/")
expect_equal(res_api$status, 200)
expect_equal(res_api$body, res_endpoint$body)
})
Expand All @@ -20,7 +20,7 @@ test_that("GET /version", {
expect_equal(res, jsonlite::unbox(as.character(packageVersion("serovizr"))))

router <- build_routes()
res_api <- router$request("GET", "/api/version/")
res_api <- router$request("GET", "/version/")
expect_equal(res_api$status, 200)
body <- jsonlite::fromJSON(res_api$body)
expect_equal(unclass(res), unclass(body$data))
Expand Down Expand Up @@ -137,7 +137,7 @@ test_that("GET /dataset/<name>/trace/<biomarker>", {

test_that("requests without trailing slash are redirected", {
router <- build_routes()
res_api <- router$request("GET", "/api/version")
res_api <- router$request("GET", "/version")
expect_equal(res_api$status, 307)
})

Expand Down
Loading