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

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
blatyo
The best overview for how things are tied together is this presentation. Modules and functions are pretty well documented at this point, ...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
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
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
aditya7iyengar
Rummage.Ecto and Rummage.Phoenix provide ways to perform Searching, Sorting and Pagination over Ecto queries and Phoenix collections. Fo...
New
zachdaniel
Ash Framework What is Ash? Ash Framework is a declarative, resource-oriented application development framework for Elixir. A resource can...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement