satom99

satom99

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!

Showing Posts 1 to 3

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 OP

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.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews