RouteDecoderModule
trait RouteDecoderModule
Instead of using just String
as path params, using the RouteDecoderModule
we can extract and converted params into a specific type also.
Http.collect[Request] {
case GET -> !! / "user" / int(id) => Response.text("User id requested: ${id}")
case GET -> !! / "user" / name => Response.text("User name requested: ${name}")
}
If the request looks like GET /user/100
then it would match the first case.
This is because internally the id
param can be decoded into an Int
. If a
request of the form GET /user/zio
is made, in that case the second case is
matched.
class Object
trait Matchable
class Any