I have several get
routes for my akka-http
service; they all have the form:
pathPrefix("compass") {
path("route") {
parameters(('srclat.as[Double], 'srclon.as[Double],
'destlat.as[Double], 'destlon.as[Double])) {
(srclat, srclon, destlat, destlon) =>
complete(getRoute((LatLong(srclat, srclon), LatLong(destlat,
destlon))))
}
}
}
Using Cats Validated data type, I am able to validate both the latitudes and longitudes passed to the method, collecting any values that exceed their ranges in a List[String]
. I know there's a validate
directive, but I'm not sure if it works for applicative (accumulative) style validation (so if multiple parameters are wrong, I'll get a list of all errors), but I'm not sure how to use the validate
directive for this, or if there's a preferred way.
Also, I know parameters
is a directive and should be able to be reused-- I have 3 get
methods with the same parameters (requiring the same validation), so if there's a way to accomplish this with the least amount of boilerplate, that would be great. Thanks for any suggestions!