elixirtalk icon indicating copy to clipboard operation
elixirtalk copied to clipboard

Re: Episode 123 - Ecto for param validation

Open akoutmos opened this issue 5 years ago • 0 comments

Let me start by saying as a long time listener I love the podcast and appreciate what you guys are doing!

In regards to the "Ecto!" episode, I also very much like the pattern of creating embedded schemas for endpoint param validation and then creating a plug in my controller to validate that the params coming in passed the changeset validations. The problem was, there was a TON of boilerplate that had to be copy and pasted every time I wanted to do this for every endpoint and quickly got messy.

There exists the params library (https://github.com/vic/params) but unfortunately all the library does is ensure the request payload matches the defined schema in terms of required/optional and type. So I created my own library on top of Ecto schemas :).

The library is published and on hex (https://hex.pm/packages/pharams) and the code is up on github (https://github.com/akoutmos/pharams). It's still very early on in its development, but for the most part it works great and cuts down the boilerplate considerably. Would be interested in getting feedback/input and hopefully it is useful to other people for param validation in Phoenix.

Thanks again for the podcast!

akoutmos avatar Sep 20 '18 20:09 akoutmos