Fork me on GitHub
#ring
<
2019-03-28
>
mping14:03:52

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

mping14:03:53

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?

mping14:03:11

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

mping14:03:59

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

grierson16:03:39

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

mping17:03:12

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

mping17:03:18

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

grierson17:03:05

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

grierson17:03:43

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

grierson17:03:59

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.