com-lihaoyi / cask

Cask: a Scala HTTP micro-framework. Cask makes it easy to set up a website, backend server, or REST API using Scala
https://com-lihaoyi.github.io/cask/
Other
525 stars 55 forks source link

Path with different query parameters should be considered unique #100

Open OndrejSpanel opened 8 months ago

OndrejSpanel commented 8 months ago

The overloading based on query parameters is inconsistent. When checking routes for overlaps, the parameters are ignored, yet when serving the requests, the overloads are selected based on them.

Following routes are rejected as invalid.

  @cask.get("/hello")
  def hello() = {
    "Hello World!"
  }

  @cask.get("/hello")
  def helloName(name: String) = {
    s"Hello ${name.reverse}"
  }

The error is:

More than one endpoint has the same path: get /hello, get /hello

However when I remove the helloName parameter, requests with the query parameter name are not served.

I suggest query parameters are considered similar to path segments, as following similar routes are valid:

  @cask.get("/hello")
  def hello() = {
    "Hello World!"
  }

  @cask.get("/hello/:name")
  def helloName(name: String) = {
    s"Hello ${name.reverse}"
  }