beef331 / website

Code for the official Nim programming language website
https://nim-lang.org
19 stars 1 forks source link

This month with Nim: Kraut #77

Closed moigagoo closed 1 year ago

moigagoo commented 1 year ago

Name: Kraut

Author: moigagoo

Posting:

I really want to make the web development story in Nim happen, in particular, the frontend part of it.

Although I am not a frontend developer myself, I've spent some time playing around with Karax and quickly realized there are obvious missing parts.

One of those low hanging fruit is routing. I want routing that is obvious, extensible, and unbloated.

And thus, behold Kraut. Kraut is a tiny lib that allows you to think in routes instead of hash parts and URL params instead of split strings. The routes are defined with Nim's built-in key-value sugar, so you have nothing new to learn:

let routes = {"#/path/{param}/subpath/": rendererProc,}

The requirements for the renderer price are also very simple: they must accept a Context instance and return a VNode.

See the docs and a full working example in the repo: https://github.com/moigagoo/kraut