pedestal

Ashkan Banitalebi 2020-08-17T19:06:33.016700Z

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

dangercoder 2020-08-23T08:31:59.002900Z

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

dangercoder 2020-08-23T08:32:58.003100Z

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

ikitommi 2020-08-17T19:17:48.020300Z

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

ikitommi 2020-08-17T19:18:45.020400Z

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

ikitommi 2020-08-17T19:22:37.020900Z

needs few locs of glue code, that's all

Ashkan Banitalebi 2020-08-17T20:55:13.021100Z

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