Closed greenmanspirit closed 7 years ago
I added question to the title because I don't see how to add a question label.
I think you need to define your view
method like that:
public bool view (Request req, Response, res, NextCallback next, Context context) {
// Do whatever you want with context here
}
Because context
is not a property of the Router
class, but a parameter passed to your handlers.
Bat41 is correct here, your function definition is lacking the full signature. If you don't specify the handler-specific context, it will default to the global routing context which is in the lexical scope.
I'd suggest at this point to put the route bindings in a construct {}
block such that it can let you define alternate constructors as well.
Unrelated, but I'll probably implement a builder for JSON-Api-GLIb to write payloads as expression similar to what Compose allows.
Happy hacking!
That fixed it! I based this off of the example here, http://docs.valum-framework.org/en/latest/router/#cleaning-up-route-logic.
Thanks! I am enjoying this and JSON-Api-GLib. I am working on a Kanban server to learn Meson, Vala, Valum and JSON-Api-GLib.
Try to stick on the 0.3.*
series. I'm trying to introduce a more class-based API to enable more introspection and Vala-friendly patterns in the next release.
I think this question can be marked as addressed.
Hello, I am trying to subclass Router but when I try to access my context variable, it is not there. With the code below, I am accessing it with 0.0.0.0:3000/board/1 and the view method is called.