realm-router
Realm router is a bleeding edge restful framework (ec7 + decorators), based on realm dependency injection.
Features
- Dependency injection
- Decorators that support local injection and method interception
- Promised based (no need in res.send)
- Automatic method mapping
"use realm"; ; ; @ @ @ static { return hello : "world" }
Installing
npm install realm-js realm-router --save
Feed realm middleware into express
var realm = ;var router = ; realm;
Routing
Create a class in a dedicated package.
"use realm";; @ static { return hello : "world" }
Use "@route" decorator to define a path. This is pretty straightforward path2regexp. Each http method corresponds to according static method in the class.
static {}static {}static {}static {}
Route injections
There are few "local" injections that are available
Name | Description |
---|---|
$req | express request |
$res | express response |
$query | Query getter $query.get('hello') |
$body | Body getter $body.get('hello') |
You can inject anything else using decorators
Decorators
Decorators are in realm-router are very powerful thing. You can intercept and inject dependencies into methods;
Let's create a helloWorld decorator
"use realm"; ; static { return $hello: "my new $hello injection" } static if $query return hello : "intercepted!" ;
Inject
inject method could return an object with injections. The latter ones will be injected into the target
Intercept
intercept method might return an object which will prevent the target route from being executed. An object will be displayed instead.