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

Mounted routers should require a slash for route location #476

Closed
blairj09 opened this issue Aug 16, 2019 · 3 comments · Fixed by #501
Closed

Mounted routers should require a slash for route location #476

blairj09 opened this issue Aug 16, 2019 · 3 comments · Fixed by #501
Labels
difficulty: advanced Best for maintainers to address effort: low < 1 day of work priority: low Will be fixed eventually type: enhancement Adds a new, backwards-compatible feature
Milestone

Comments

@blairj09
Copy link
Collaborator

blairj09 commented Aug 16, 2019

On MacOS 10.14.16 with R 3.6.1 and Plumber 0.4.6, mounted routers are inaccessible. Consider the following example:

library(plumber)

root <- plumber$new()

# Mount first
first <- plumber$new()
first$handle("GET", "/echo", function(msg = "") {
  list(msg = paste0("The message is '", msg, "'"))
})
root$mount("first", first)

# Mount second
second <- plumber$new()
second$handle("GET", "/add", function(x, y) {
  as.numeric(x) + as.numeric(y)
})
root$mount("second", second)

root
#> # Plumber router with 0 endpoints, 4 filters, and 2 sub-routers.
#> # Call run() on this object to start the API.
#> ├──[queryString]
#> ├──[postBody]
#> ├──[cookieParser]
#> ├──[sharedSecret]
#> ├──/first
#> │  │ # Plumber router with 1 endpoint, 4 filters, and 0 sub-routers.
#> │  ├──[queryString]
#> │  ├──[postBody]
#> │  ├──[cookieParser]
#> │  ├──[sharedSecret]
#> │  └──/echo (GET)
#> ├──/second
#> │  │ # Plumber router with 1 endpoint, 4 filters, and 0 sub-routers.
#> │  ├──[queryString]
#> │  ├──[postBody]
#> │  ├──[cookieParser]
#> │  ├──[sharedSecret]
#> │  └──/add (GET)

This seems to indicate that echo would be available at /first/echo and add would be available at /second/add. However, when trying to access either of those endpoints, a 404 error is returned:

curl -X GET 'http://localhost:5762/first/echo?msg=hi'
{"error":["404 - Resource Not Found"]}
curl -X GET 'http://localhost:5762/second/add?x=1&y=9'
{"error":["404 - Resource Not Found"]}
@schloerke schloerke changed the title Mounted routers don't work Mounted routers should require a slash for route location Aug 19, 2019
@schloerke
Copy link
Collaborator

schloerke commented Aug 19, 2019

The code below works.

library(plumber)

root <- plumber$new()

# Mount first
first <- plumber$new()
first$handle("GET", "/echo", function(msg = "") {
  list(msg = paste0("The message is '", msg, "'"))
})
root$mount("/first", first)

root$run(port = 7400)

Maybe add a starting slash to all endpoints / mounts if it is missing?

@schloerke schloerke added difficulty: advanced Best for maintainers to address effort: low < 1 day of work priority: low Will be fixed eventually type: enhancement Adds a new, backwards-compatible feature labels Aug 19, 2019
@sravangottipaty

This comment has been minimized.

@schloerke
Copy link
Collaborator

schloerke commented Aug 26, 2019

@sravangottipaty Can you phrase your question in a different way? I don't fully understand it. Thank you!

The error above was caused by calling root$mount("first"). When $mount should require that the route starts with a slash (/), ex: root$mount("/first"). I'd like for plumber to produce an error when mounting path does not start with a slash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: advanced Best for maintainers to address effort: low < 1 day of work priority: low Will be fixed eventually type: enhancement Adds a new, backwards-compatible feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants