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

OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
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
ityonemo
Currently just starting out on a new mini-project - getting zig NIFs to run in elixir. https://github.com/ityonemo/zigler The idea here...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
dbern
I’m excited to announce that TaxJar has developed and open-sourced DateTimeParser. We developed it because we found a need to parse user ...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: GitHub - devonestes/assertions: Helpful a...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
treble37
Just looking for a little feedback on a tiny helper library I built - Sometimes I find the need to convert maps with atom keys to maps w...
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

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
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
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement