# methodulus

Latest version **1.0.16** (published 2017-09-09) · (MIT OR Apache-2.0) license · 0 weekly downloads

## Install

```sh
npm install methodulus
pnpm add methodulus
yarn add methodulus
bun add methodulus
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.16 |
| Published | 2017-09-09 |
| First published | 2017-07-19 |
| Weekly downloads | 0 |
| License | (MIT OR Apache-2.0) |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 26 |
| Known vulnerabilities | 0 (+4 in 4 direct dependencies) |
| Install scripts | no |
| GitHub stars | 22 |
| Author | nodulusteam |
| Maintainers | nodulus |
| Keywords | nodulus, rpc, microservice, microservices framework |

## Links

- npm: https://www.npmjs.com/package/methodulus
- Repository: https://github.com/nodulusteam/methodulus
- Homepage: https://nodulusteam.github.io/methodulus/
- Issues: https://github.com/nodulusteam/methodulus/issues
- npm.io page: https://npm.io/package/methodulus

## Dependencies (26)

- [nedb](https://npm.io/package/nedb.md) ^1.8.0
- [uuid](https://npm.io/package/uuid.md) ^3.1.0
- [debug](https://npm.io/package/debug.md) ^2.6.8
- [redis](https://npm.io/package/redis.md) ^2.7.1
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [figlet](https://npm.io/package/figlet.md) ^1.2.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [amqplib](https://npm.io/package/amqplib.md) ^0.5.1
- [express](https://npm.io/package/express.md) ^4.15.3
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.9.0
- [logelas](https://npm.io/package/logelas.md) ^1.0.20
- [request](https://npm.io/package/request.md) ^2.81.0
- [shortid](https://npm.io/package/shortid.md) ^2.2.8
- [tap-dot](https://npm.io/package/tap-dot.md) ^1.0.5
- [socket.io](https://npm.io/package/socket.io.md) ^2.0.3
- [kafka-node](https://npm.io/package/kafka-node.md) ^2.2.2
- [body-parser](https://npm.io/package/body-parser.md) ^1.17.2
- [compression](https://npm.io/package/compression.md) ^1.7.0
- [errorhandler](https://npm.io/package/errorhandler.md) ^1.5.0
- [mock-require](https://npm.io/package/mock-require.md) ^2.0.2
- [nedb-promise](https://npm.io/package/nedb-promise.md) ^2.0.1
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.3
- [method-override](https://npm.io/package/method-override.md) ^2.3.9
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.10
- [socket.io-client](https://npm.io/package/socket.io-client.md) ^2.0.3
- [request-promise-native](https://npm.io/package/request-promise-native.md) ^1.0.4

## Recent versions

- 1.0.16 (latest) — 2017-09-09
- 1.0.15 — 2017-09-08
- 1.0.14 — 2017-07-26
- 1.0.13 — 2017-07-25
- 1.0.12 — 2017-07-22
- 1.0.11 — 2017-07-22
- 1.0.10 — 2017-07-22
- 1.0.9 — 2017-07-22
- 1.0.8 — 2017-07-21
- 1.0.7 — 2017-07-21
- 1.0.6 — 2017-07-21
- 1.0.5 — 2017-07-21
- 1.0.4 — 2017-07-21
- 1.0.3 — 2017-07-21
- 1.0.2 — 2017-07-20
- … 2 more at https://npm.io/package/methodulus/versions

## README

# Methodulus

<a href="https://travis-ci.org/nodulusteam/methodulus">
<img src="./examples/resources/methodulus.png" alt="Drawing" style="max-width: 200px!important;"/>
</a>

[<img src="https://travis-ci.org/nodulusteam/methodulus.svg?branch=master">](https://travis-ci.org/nodulusteam/methodulus)
 

### motivation
* we want microservices!
* we need a dynamic system architecture!
* we want it all!


### automatic server to server connectivity using a dynamic rpc transport layer



`npm i -S methodulus`


<img src="./examples/resources/slide1.png">


#### Hello methodulus

> This example creats a rest (express based) server using a controller class `Player`
>
> it is configured to run the class code locally via an http server.
 

```javascript
import { Player } from './controllers/player';
import { ServerConfig, ClientConfig, ConfiguredServer, MethodType, ServerType } from 'methodulus';

@ServerConfig(ServerType.Express, { port: process.env.PORT || 8020 })
@ClientConfig(Player, MethodType.Local)
class SetupServer extends ConfiguredServer {

}

new SetupServer();

```

#### the Player class
```javascript
import { Body, Method, MethodConfig, MethodType, Param, Query, Verbs, MethodError, MethodResult } from 'methodulus';
import { PlayerModel } from '../models/player';


@MethodConfig('Player')
export class Player {
    @Method(Verbs.Post, '/api/player')
    public async create() {
        let p = new PlayerModel('1', 'player 1');
        await DB.Player.insert(p);
        return new MethodResult(p)
    }

    @Method(Verbs.Get, '/api/player/:player_id')
    public async read( @Param('player_id') playerId: number) {
        return await DB.Player.find({ 'Id': playerId });
    }

    @Method(Verbs.Put, '/api/player')
    public async update() {

    }


    @Method(Verbs.Delete, '/api/player')
    public delete() {

    }



}

```
 




# Classes & API

## ConfiguredServer

this class is the base class for the server implementation. it uses the Server & Client decorators to apply the desired configuration.

### @Server(ServerType, options)
syntetic suger for MethodulusConfig.run() function.


### @Client(ClassType, MethodType, resolver?)
syntetic suger for MethodulusConfig.use() function.



## MethodulusConfig
> configuration must complete before the server starts.
> configure each controller class to its desired state

```javascript
let config = new MethodulusConfig()
```

### .run(ServerType, options)
the run method determines what kind of server to run on the listening part of the application. to listen to REST request you should run `ServerType.Expess` and to listen to redis channel use `ServerType.Redis`  .


#### ServerType
* `Express`
* `Redis`
* `MQ`
* `Socket`


### .use(classType, MethodType, resolver)
the use method registers the way a class should be activated.
the first parameter is a class decorated with methodulus decoratos.


#### MethodType
> avaliable options are  `Local | Http | MQ | Socket | Redis`
* `Local`
run the code in the class, no proxy or transport required.

* `Http`
run the code using an http request to a microservice.

* `MQ`
use amqp rpc to execute the class code

* `Socket`
directly connect to a server using websocket connection.

* `Redis`
use redis rpc to execute the class code

#### Resolver
in order to access the correct service methodulus uses a resolver, which may be a literal containing the service uri or a promise returning the same.

resolvers are attached to a class, allowing the application to use different resolvers for different services.
```

```



### Available servers
an instamce of methodulus can run multiple listeners in different channels. the current list is:
* `express`
* `socketio`
* `amqp`
* `redis`


> here is a simple local configuration:
> The class `Player` will execute locally.
```
let servers = ['express']; 
let config = new MethodulusConfig(servers);
let resolver = 'http://127.0.0.1:8090';
config.run(ServerType.express, {port: process.env.PORT })
config.use(TestClass, MethodType.Local,resolver);

```



## Server
> creates an agnostic configured server.
```
const server = new Server(process.env.PORT);
```

Server methods are chainable and should e called in this order
```
const server = await new Server(process.env.PORT).configure(config).start();
```
# Decorators
## Class decorators
### @MethodConfig
decorating a class with the decorator will turn it into a methodulus end point.
```javascript
@MethodulusConfig(applicationname, [middlewares]?)
```

### @Method
Each decorated method in the MethodConfig decorated class will become a function endpoint of the methodulus application.

```
@Method(Verb, route, [middlewares])
```
## Parameter decorators
a decorated method should use the following parameter decorators to indicate the source of each argument.

### @Query

### @Param

### @Body
### @Request
### @Response

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