
Security News
Feross on TBPN: Socket's Series C and the State of Software Supply Chain Security
Feross Aboukhadijeh joins TBPN to discuss Socket's $60M Series C, 500%+ ARR growth, AI's impact on open source, and the rise in supply chain attacks.
@methodus/server
Advanced tools
Methodus is a micro-service & RPC framework, so let's build a micro-service from scratch using this beautiful framework.
Methodus uses controllers in the same manner the express framework does. It binds functions or class methods to a route. and then routes the requests to these functions.
in Methodus it will look like this
import { Method, MethodConfig, Files, Verbs, MethodType, Body, Response, Request, Param, Query, SecurityContext, MethodError, MethodResult } from '@tmla/methodus';
/*start custom*/
//in here you can put types and definitions that should be distributed with the contract
/*end custom*/
import * as fs from 'fs';
import * as path from 'path';
@MethodConfig('@tmla-tiles/hellow-world')
export class Hello {
@Method(Verbs.Post, '/api/hello', [upload.any(), autoReap]) //loading route and middlewares
public static async upload( @Files('0') file: any, @Query('originalname') originalname: string, @Query('keep_original') keepOriginalName: boolean = true) {
return new MethodResult(result);//return the result
};
@Method(Verbs.Get, '/api/hello/:file_id')
public static async getById( @Param('file_id') file_id) {
return new MethodResult(result);
};
@Method(Verbs.Get, '/api/hello/name/:file_name/')
public static async getByName( @Param('file_name') file_name, @SecurityContext() att) {
return new MethodResult(result);
};
@Method(Verbs.Delete, '/api/hello/id/:file_id')
public static async delete( @Param('file_id') file_id, @SecurityContext() att) {
return new MethodResult(deleteResult);
};
}
The controller class is decorated with a @MethodConfig decorator stating the name of the npm package the controller refers to. Each method is then decorated with a @Method decorator and the route parameters (Http verb, path, middlewares). The arguments passed into these decorated methods will be mapped according to the argument variables that precede them.
same as body in express, a name can be passed to get a specific key within the body object| Decorator | Verb | Description |
| @Body() | Post | |
| @Query() | All | All same as query in express, a name can be passed to get a specific key within the query object |
| @Param() | All | All same as param in express, a name can be passed to get a specific key within the param object. |
| @File() | Post | same as files in express + multer , a name can be passed to get a specific key within the body object |
| @SecurityContext() | All | same as using req.att in our traditional cntrollers. the security context is built using the @tmla/secure middleware, therefor in order to use it the middleware should be used. |
| Special Mappings | ||
| @Response() | All | same as res in express, the mapping should be used when we need to pipe a stream to the response |
| @Request() | All | same as req in express, the mapping should be used when we need to pipe a stream to the request |
A Methodus method should return an object of type MethodResult. this object can be used to set the status code for the response as well as paging and total records information.
@Method(Verbs.Get, '/api/hello/name/:file_name/')
public static async getByName( @Param('file_name') file_name, @SecurityContext() att) {
return new MethodResult(result);
};
Methodus methods are automatiaclly loged using the Trace log level. you may have noticed the use of static methods for the controller class. this is not mandatory as you may use either static or instance approach, as long as you do that for all the methods in the class. Server activation The controller is ready, let's bind it to a methodus server. in our node app we create an entry point in the form of host.ts file. this host file starts an express server using the configured port and binds our controller to it.
import { ServerType, Server, MethodType, MethodusConfig } from '@tmla/methodus';
import { Hello } from './controllers/hello-controller';
const configuration = require('@tmla/config').config;
(async () => {
let config = new MethodusConfig();
config.run(ServerType.Express, { port: +configuration.port });
config.use(Hello, MethodType.Local, ServerType.Express);
let server = await new Server(+configuration.port).configure(config).start();
})()
the async function is an IIFE ( Immidiatly Invoked Function Expression) that executes the server code, but you may use any invocation method you see fit. if all goes well you should see
__ _ _|_|_ _ _| _
|||(/_ |_| |(_)(_||_|_>
Starting REST server on port xxxx
which means that every thing wen well and you're ready to browser or postman your routes.
Your microservice ready, but if it is to be consumed using the Methodus rpc it need's to generate a contract.
FAQs
Server components for @methodus workflow
The npm package @methodus/server receives a total of 170 weekly downloads. As such, @methodus/server popularity was classified as not popular.
We found that @methodus/server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

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.

Security News
Feross Aboukhadijeh joins TBPN to discuss Socket's $60M Series C, 500%+ ARR growth, AI's impact on open source, and the rise in supply chain attacks.

Security News
OSV withdrew 157 OSV malware reports after automated false positives incorrectly flagged trusted npm and PyPI packages, sending bad records into tools that rely on OSV data.

Research
/Security News
TrapDoor crypto stealer hits 36 malicious packages across npm, PyPI, and Crates.io, targeting crypto, DeFi, AI, and security developers.