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

Error parsing BigDecimal path arguments #120

Closed aaronp closed 5 months ago

aaronp commented 6 months ago

Consider the following route:

  @cask.get("/echo/:x")
  def echo(x: BigDecimal) = x.toString

the route macro will fail with the following error on initialization:

[error] 47 |  initialize()
[error]    |  ^^^^^^^^^^^^
[error]    |  no reader of type scala.math.BigDecimal found for parameter x

It seems BigDecimal should be supported by default, and the documentation would benefit from clear instructions on how to add new path parsers for different types.

(And my apologies if I've just been to thick to find it! Thanks so much for the fantastic platform)

lihaoyi commented 5 months ago

I think you need to define an implicit QueryParamReader for BigDecimalhttps://github.com/com-lihaoyi/cask/blob/1b13abceb474be306b33c2aa197b583602b26be1/cask/src/cask/endpoints/WebEndpoints.scala#L52-L56

aaronp commented 5 months ago

Thanks so much Li - closing this issue