ring

2019-03-28T14:14:52.000500Z

how do you guys deal with request validation? use spec? schema? monads? exceptions?

2019-03-28T14:15:53.001800Z

suppose I'm deep in the code, and I want to invalidate the current request being processed. do you throw an exception and use a catch-all to map the ex-data to a 400 bad request or something?

2019-03-28T14:16:11.002200Z

I have the idea that exceptions may be a bit costly, besides its basically a goto

2019-03-28T14:41:59.002500Z

this reading was quite interesting, specially the inline bit https://shipilev.net/blog/2014/exceptional-performance/

grierson 2019-03-28T16:47:39.007100Z

@mping This is something I have been looking into recently. I have started using Reitit + Interceptors. Reitit and Spec for coercion and data validation at the front door then Interceptors for more ?'advanced validation'? such as making queries to a databases then performing validation with that data. If an error occurs just throw an exception and return the context in the :enter function and return a 400 in the :error function.

2019-03-28T17:03:12.007800Z

@grierson tks I'll take a look; do u have some reference gist/project?

2019-03-28T17:04:18.008400Z

I'm using compojure-api in one proj but sometimes you dont want to validate at the "front door"

grierson 2019-03-28T17:06:05.009100Z

@mping The reitit github has some documentation for coercion and validation. https://github.com/metosin/reitit

grierson 2019-03-28T17:06:43.010Z

but for Interceptors + Exceptions they don't have any. I had loads of trouble finding resources.

grierson 2019-03-28T17:07:59.010600Z

In terms of "sometimes you dont want to validate at the "front door", it's optional in Reitit you don't have to if you don't want to.