valum-framework / valum

Web micro-framework written in Vala
https://valum-framework.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
225 stars 23 forks source link

Provide a routing context instead of a stack #147

Closed arteymix closed 8 years ago

arteymix commented 8 years ago

The context provide a hierarchical mapping of states shared among handlers. It is possible to access the parent context.

var context = new Context ();

var context_with_parent = new Context.with_parent (context);

All operations are recursively applied. If a key is missing in the current context, it is retrieved in its parent.

app.use ((req, res, next, context) => {
    context["id"] = "6";
    next (req, res);
});

app.get ("user/<int:id>", (req, res, next, context) => {
    var user_id = context["id"].get_string ();
    context.parent["id"]; // refers to '6'
});

It completely replace Request.params, which has been removed.