finch icon indicating copy to clipboard operation
finch copied to clipboard

Replace ValidationRule with Cat's Validated

Open vkostyukov opened this issue 9 years ago • 5 comments

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 avatar Jan 29 '16 18:01 vkostyukov

@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.

ilya-murzinov avatar Oct 13 '16 21:10 ilya-murzinov

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.

vkostyukov avatar Jan 03 '18 05:01 vkostyukov

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?

sergeykolbasov avatar Jan 03 '18 09:01 sergeykolbasov

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.

prayagupa avatar Oct 15 '18 01:10 prayagupa

@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

sergeykolbasov avatar Oct 15 '18 07:10 sergeykolbasov

Validation removed in #1471

joroKr21 avatar Sep 16 '22 12:09 joroKr21