# realm-router

> Realm router is a bleeding edge restful framework (ec7 + decorators), based on realm dependency injection.

Latest version **1.1.35** (published 2016-08-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install realm-router
pnpm add realm-router
yarn add realm-router
bun add realm-router
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.35 |
| Published | 2016-08-30 |
| First published | 2016-05-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | nchanged |

## Links

- npm: https://www.npmjs.com/package/realm-router
- Repository: https://github.com/realm-js/realm-router
- Issues: https://github.com/realm-js/realm-router/issues
- npm.io page: https://npm.io/package/realm-router

## Dependencies (9)

- [jsep](https://npm.io/package/jsep.md) ^0.3.0
- [swig](https://npm.io/package/swig.md) ^1.4.2
- [chalk](https://npm.io/package/chalk.md) ^1.1.3
- [lodash](https://npm.io/package/lodash.md) ^4.12.0
- [log4js](https://npm.io/package/log4js.md) ^0.6.36
- [promise](https://npm.io/package/promise.md) ^7.1.1
- [realm-js](https://npm.io/package/realm-js.md) ^1.1.97
- [parsetrace](https://npm.io/package/parsetrace.md) ^0.2.0
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^1.3.0

## Recent versions

- 1.1.35 (latest) — 2016-08-30
- 1.1.34 — 2016-08-30
- 1.1.33 — 2016-08-30
- 1.1.32 — 2016-07-27
- 1.1.31 — 2016-07-27
- 1.1.30 — 2016-07-27
- 1.1.29 — 2016-07-26
- 1.1.28 — 2016-07-25
- 1.1.27 — 2016-06-20
- 1.1.26 — 2016-06-20
- 1.1.25 — 2016-06-14
- 1.1.24 — 2016-05-26
- 1.1.23 — 2016-05-25
- 1.1.22 — 2016-05-25
- 1.1.21 — 2016-05-24
- … 8 more at https://npm.io/package/realm-router/versions

## README

# 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


```js
 "use realm";

 import route, cors from realm.router.decorators;
 import Session as session from realm.test;

 @route("/")
 @cors()

 class MainRouter {

    @session()
    static get($session, $params, $query, $body) {
       return { hello : "world"}
    }
 }
 ```

## Installing

 ```bash
 npm install realm-js realm-router --save
 ```

 Feed realm middleware into express

 ```js
 var realm  = require('realm-js');
 var router = require('realm-router');

 realm.require('realm.router.Express', function(router) {
    app.use(router("your.package.with.routes", {
       prettyTrace: true
    }))
});
  ```

## Routing

Create a class in a dedicated package.
```js
"use realm";
import route from realm.router.decorators;

@route("/")
class MainRouter {
   static get() {
      return { hello : "world"}
   }
}
export MainRouter
```

Use "@route" decorator to define a path. This is pretty straightforward path2regexp.
Each http method corresponds to according static method in the class.
```js
static get() {}
static post() {}
static put() {}
static delete() {}
```

## 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
```js
"use realm";

import Decorator from realm.router;
class HelloWorld {

   static inject() {
      return {
         $hello: "my new $hello injection"
      }
   }

   static intercept($query)
   {
      if( $query.get('hello') ){
         return {hello : "intercepted!"}
      }
   }
}

export Decorator.wrap(HelloWorld);
```
### 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.

---
_Source: https://npm.io/package/realm-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
