Finch.io 0.1.3
This release contains several functional improvements:
ValidationRule
accepts param
name in order to pass it into the exception. So, a fancy errors may be generated out the expections ParamNotFound
and ValidationFailed
val params = for {
name <- RequiredParam("name")
_ <- ValidationRule("name", "should be longer then 5 chars") { name.length > 5 }
} yield name
val a = new Service[HttpRequest, HttpResponse] {
def apply(req: HttpRequest) = for {
name <- params(req)
} yield Ok()
}
val req: HttpRequest = ???
a(req) handle {
case e: ParamNotFound => BadRequest(s"${e.param} not found")
case e: ValidationFailed => BadRequest(s"${e.param} is not validated: ${e.rule}")
}
Also, a Respond
builder may consume HTTP headers with withHeaders
method:
val ok: Respond = Ok.withHeaders("Header-A" - > "a", "Header-B" -> B)
val rep: HttpRequest = ok()
Also, a new right-hand-side operand for pipe !
operator is pure service. Services, filters and endpoints may be piped to other service like following.
Composing services:
val ab: Service[A, B] = ???
val bc: Service[B, C] = ???
val ac: Service[A, C] = ab ! bc
Composing endpoints:
val ab: Endpoint[A, B] = ???
val bc: Endpoint[B, C] = ???
val ac: Endpoint[A, C] = ab ! bc
Finally, TurnJsonIntoHttp
is no longer a filter but pure service. So, it may be constructred without request type.