satom99

satom99

Paramus - Parameter validation for Phoenix!

Dealing with parameter validation in Phoenix controllers is a rather tedious task, especially when dealing with multiple parameters, types, default values and additional validations one may need. Therefore having a library handle all of this automatically is basically a necessity - which is where paramus comes in handy.

Repository: GitHub - satom99/paramus: Parameter validation for Phoenix · GitHub

Contributions are more than welcome, as always!

Most Liked

anandtrex

anandtrex

@satom99 Looks really nice. Any plans to put it on hex.pm?

mythicalprogrammer

mythicalprogrammer

I’m curious on when would I use this when ecto schema have type and validation no?

I’m also coming from php and old school MVC framework where the idea is fat model and skinny controller.

Is there any benefit over ecto schema and changeset validation?

Thanks for the contribution

satom99

satom99

Sure thing! It is now available on hex here :slightly_smiling_face:.


I presume we’re discussing a case where you’d put the params directly through an ecto schema’s changeset before insterting or updating a specific resource - say per example creating a user.

If that’s the case, you could go without paramus just fine. However, in the event that a changeset validation fails, if you are using the bangified functions (i.e. Repo.insert/1) an error will be raised, then picked up by Phoenix and turned into a response code of 422 - which is fine for most cases. But if you wanted to return a message explaining what was wrong, you’d use the non-bangified functions and typically match in a case statement whether the operation failed and then traverse the changeset’s errors manually and whatnot - and this clearly results in repeated code if needed on multiple places.

So as a tldr I would add that paramus comes in handy (when acting against ecto schemas) “only” if you want to be able to display changeset errors without having to handle the logic yourself.


All of this being said; I myself also use paramus on non-ecto-schema-related handlers. Per example, say I have an endpoint that interacts with a running GenServer and that I want the received data to be in a specific format. Lets consider this example, I could have a server “storing” fruits and very easily call that consume endpoint with a name, quantity and possibly a cut? value and pass all of these directly to the server without having to care about validating the data manually.


Also I haven’t really specified this before but, paramus refers to the project’s ErrorView to handle the changeset errors - have a look here. So if, as mentioned, you wanted to display changeset errors, because the changeset is passed down as a parameter to the error view, you could traverse it there.

Where Next?

Popular in Announcing Top

wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
Crowdhailer
The latest release of Ace (0.10.0) includes serving content over HTTP/2. I have started writing a webserver to teach my self more about...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 18934 194
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
Qqwy
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects. Core ideas Type- and function specifications are const...
336 14482 100
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31013 112
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement