Replace ValidationRule with Cat's Validated
I don't have a particular solution in mind, but I think it's worth to have an opened ticket for this before we forget. I eagerly want to replace Finch's data types with the ones community share and understand. ValidationRule is a good candidate to be reaplced (in some way) with Cat's Validated.
@vkostyukov can you please clarify how exactly do you see this possible?
I don't get it, because finch's ValidationRule is just a some kind of convenient DSL for combining boolean predicates, but cats' Validated is a data type which encodes validation result.
I think what we should aim for is to have default endpoints (i.e., param, header) returning Endpoint[ValidatedNel[Error, A]] instead of Endpoint[A]. A very similar (yet simpler) approach is described in this gist.
What about the composition of endpoints? Let's say I have:
get(param("foo") :: header("bar")) { (foo: A?, bar: B?) => {
...
}
}
What is a type of A? and B? here?
I liked Finch: A Life Without Exceptions. I was thinking the same when I was first looking for REST libraries in scala, but none of them do that.
Then what I could not figure out is provide a way to encode response along with the http codes.
If we define an http endpoint is of type Either[Error, a], a is 2xx but what is going to be Error http code? And we might at least need types for "2xx, 4xx and 5xx". Maybe there is a way I could not think of.
@prayagupd Yes, status should be a part of an error.
In our project services always return F[Either[Error, A]] where Error <: Throwable is a type that guarantees status, description etc. And then we just fold it into Output using Output.payload or Output.failure
Validation removed in #1471