Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

methodulus

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

methodulus

Source
npmnpm
Version
1.0.14
Version published
Weekly downloads
16
220%
Maintainers
1
Weekly downloads
 
Created
Source

Methodulus

Drawing

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

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.

import { Player } from './controllers/player';
import { Server, MethodulusConfig, MethodulusClassConfig, MethodType } from 'methodulus';

let config = new MethodulusConfig(['rest']);
config.use(Player, MethodType.Local, 'http://localhost:8090')
const server = new Server(process.env.PORT || 8020).configure(config).start();


the Player class

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

MethodulusConfig

configuration must complete before the server starts. configure each controller class to its desired state

Available servers

an instamce of methodulus can run multiple listeners in different channels. the current list is:

  • express
  • socketio
  • amqp
  • redis

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.

here is a simple local configuration:

let servers = ['express']; 
let config = new MethodulusConfig(servers);
let resolver = 'http://localhost:8090';
config.use(TestClass, MethodType.Local,resolver);

The class Player to run locally.

MethodType

avaliable options are Local | Http | MQ | Socket

  • 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

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 = new Server(process.env.PORT).configure(config).start();

Decorators

Class decorators

@MethodConfig

@Method

Parameter decorators

@Query

@Param

@Body

@Request

@Response

Keywords

nodulus

FAQs

Package last updated on 26 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts