Fork me on GitHub
#pedestal
<
2020-08-17
>
Ashkan Banitalebi19:08:33

Hi all, With the risk of this question being totally annoying and basic, what is the best practice for input validation in pedestal? I think I'll be using spec of each request input (the body) and I want for each API to have its own input validation. What I found, looking online was: https://github.com/oliyh/pedestal-api and https://github.com/metosin/reitit have some utilities for input/output validation and, mainly, coercion. However, I think I'd be better off writing my own interceptor(s) validating data. Am I missing something here? Thanks in advance. 🍻

dangercoder08:08:59

I rolled my own interceptor for this, it's based on spec/conform

dangercoder08:08:58

and expo.. re-invented the wheel a little bit since I know reitit has similar functionality.

ikitommi19:08:48

@ashkan.dant3 spec doesn't support runtime value transformations, so if you want to roll your own solution, you should pick one of the spec coercion libs out there.

ikitommi19:08:45

I believe you can just pick the reitit spec request & response coercion interceptors and use them with vanilla pedestal.

ikitommi19:08:37

needs few locs of glue code, that's all

Ashkan Banitalebi20:08:13

Thanks @U055NJ5CC, that's very helpful. Since coercion is not my focus (mainly just validation), I think any of these options would do nicely.