ElixirTalk / elixirtalk

ElixirTalk Podcast
https://soundcloud.com/elixirtalk
40 stars 2 forks source link

Re: Episode 123 - Ecto for param validation #44

Open akoutmos opened 6 years ago

akoutmos commented 6 years ago

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!