how do you guys deal with request validation? use spec? schema? monads? exceptions?
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?
I have the idea that exceptions may be a bit costly, besides its basically a goto
this reading was quite interesting, specially the inline bit https://shipilev.net/blog/2014/exceptional-performance/
@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.
@grierson tks I'll take a look; do u have some reference gist/project?
I'm using compojure-api in one proj but sometimes you dont want to validate at the "front door"
@mping The reitit github has some documentation for coercion and validation. https://github.com/metosin/reitit
but for Interceptors + Exceptions they don't have any. I had loads of trouble finding resources.
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.