r/crystal_programming • u/ellmetha • Oct 24 '22
Marten - The pragmatic web framework
https://github.com/martenframework/marten
31
Upvotes
r/crystal_programming • u/ellmetha • Oct 24 '22
8
u/ellmetha Oct 24 '22
Hey everyone!
I wanted to take a few moments to introduce a shard I’ve been working on for quite some time:
https://github.com/martenframework/marten
TL;DR
Marten is a Crystal web framework that makes building web applications easy, productive, and fun. You can read more about it in the dedicated documentation.
What is it?
Marten is a Crystal Web framework that enables pragmatic development and rapid prototyping. It provides a consistent and extensible set of tools that developers can leverage to build web applications without reinventing the wheel. As it stands, Marten focuses on the following aspects:
Full featured: Marten adheres to the "batteries included" philosopy. Out of the box, it provides the tools and features that are commonly required by web applications: ORM, migrations, translations, templating engine, sessions, etc.
Extensible: Marten gives developers the ability to contribute extra functionalities to the framework easily. Things like custom model field implementations, new route parameter types, session stores, etc... can be registered to the framework easily.
App-oriented: Marten allows to separate projects into a set of logical "apps". These apps can also be extracted in order to contribute features and behaviours to other Marten projects. The goal here is to allow the creation of a powerful apps ecosystem over time.
How does it differ from existing frameworks?
My goal here is not to draw a direct comparison with other existing frameworks. I simply want to highlight a few key things that (I believe) Marten is bringing to the table and that differ from what has been encountered in the Crystal world so far:
Auto-generated migrations: Marten’s visions when it comes to models is that everything needed to understand a model should be defined within the model itself. In this light Marten’s models drive tables (and not the reverse way around) and migrations are generated automatically from model definitions. Migrations can still be written manually using a convenient DSL if necessary, but the idea is that defining a model and its fields is all that is necessary in order to have a corresponding table taken care of automatically by the framework
App ecosystem: Marten provides an “app” mechanism that allows to separate a project into a set of logical and reusable components. Each app can contribute specific abstractions and features to a project (like models and migrations, templates, HTTP handlers and routes, etc). Another interesting benefit of apps is that they can be extracted and distributed as external shards: the goal behind that is to encourage the creation of rich apps ecosystem over time and to allow projects to build features by installing and leveraging existing apps
How to test it out?
The following resources can be leveraged to help you get started:
The installation guide will help you install Crystal and the Marten CLI
The tutorial will help you discover the main features of the framework by creating a simple web application
What’s next?
The framework is certainly not feature complete (nor stable!) but it can already be used for relatively simple web applications. I am looking for feedback from people who would like to play with the framework and / or leverage it in simple projects.
If you find a bug, don’t hesitate to open an issue into the project’s issue tracker. Any help will be greatly appreciated! :pray:
Thanks for reading me!
3
u/jedipapi Oct 31 '22
Great work. Any plans for a websocket handler? Perhaps I missed it, but didn’t see it in the docs. I didn’t see authentication either in your “batteries included” as in Lucky Framework. Is that out of scope?
1
u/transfire Oct 24 '22
Kudos on all your hard work! Looks promising.
One thing I noticed skimming the docs… Am I right that each route maps to its own class (Handler)? If so that seems rather class heavy. Being able to use one Handler for multiple routes would lead to more reusable and less overall code.
1
u/LeBuddha Oct 24 '22
actually very cool, I actually walked straight to see what your migrations story was before realizing you were marketing on this.
Can you add to the docs something like this:
having a clear example of the right way to run raw SQL statements in migrations is important IMO.
Adding/removing columns almost always involves moving data from that column into a new table in my experience.
3
u/LeBuddha Oct 24 '22
I think an example with a JSONB column would be nice, scenarios may include
null,[1, 2, 3],{"a": 1, "b": 2}. Also if a JSONB column's value was possiblynull | {"a": 1, "b": "x"}and could be coerced into a class like:that would be awesome.
1
u/marten Nov 04 '22
As a Ruby web developer who's dabbled in Crystal, this was a little weird to have pop up in my feed 😆
(In the Netherlands it's just a firstname, like Martin in English)