New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

trmi-http

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trmi-http

This is an HTTP RMI implementation based on [Fastify](https://github.com/fastify/fastify).

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

trmi-http npm

This is an HTTP RMI implementation based on Fastify.

Installation

yarn add trmi-http
npm i trmi-http

Getting started

You can find a more detailed example here.

Define and implement a remote service

type HelloResponse = {
    message: string;
}

interface HelloWorldSpecification {
    hello(world: string): Promise<HelloResponse>;
    bye(): Promise<void>;
}
import { RemoteService, RemoteMethod } from 'trmi-http';

@RemoteService()
class HelloWorld implements HelloWorldSpecification {
    @RemoteMethod()
    async hello(world: string): Promise<HelloResponse> {
        return {
            message: `Hello ${world}!`,
        };
    }

    @RemoteMethod()
    async bye(): Promise<void> {
        throw new Error('"bye" method is not implemented');
    }
}

Start a remote service server

import { HttpRemoteServer } from 'trmi-http';

HttpRemoteServer.create({ port: 3478 })
    .from(HelloWorld) // it is possible to pass varargs here
    .start()
    .catch(e => console.error('Failed to start a server', e));

Start a remote client

import { HttpRemoteServer } from 'trmi-http';

const client = HttpRemoteClient.create({ url: 'http://127.0.0.1:3478' }).start();

const helloWorld = client.getService<HelloWorldSpecification>('HelloWorld');
const response = await helloWorld.hello('world');

console.log(response.message);

helloWorld.bye().catch(console.log);

Configuration

Remote service name

By default, the remote service name defaults to the class name. You can override this behaviour by passing a name property. Characters .~ are restricted as they are used in internal key generation.

@RemoteService({ name: 'MyServer_HelloWorld' })
class HelloWorld implements HelloWorldSpecification
client.getService<HelloWorldSpecification>('MyServer_HelloWorld');

Authorization

By default, server accepts requests from everywhere. You can change that by passing a AuthorizationProvider instance.

HttpRemoteServer.create({ authorization: TokenAuthorizationProvider.create('secret'), ... });
HttpRemoteClient.create({ authorization: TokenAuthorizationProvider.create('secret'), ... });

Implementation

Server uses Fastify to receive requests from clients.

Client uses got to send requests.

Keywords

typescript

FAQs

Package last updated on 30 May 2021

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