All Projects → Insidexa → nestjs-rpc

Insidexa / nestjs-rpc

Licence: MIT license
NestJS Json RPC package

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to nestjs-rpc

finance-project-ddd
Projeto financeiro usando domain driven design, tdd, arquitetura hexagonal e solid
Stars: ✭ 67 (+42.55%)
Mutual labels:  nestjs
React-Nest-Admin
admin project powered by 🚀 React + Nestjs + Antd 全栈中后台,后端项目:https://github.com/cnscorpions/React-Nest-Admin-be
Stars: ✭ 37 (-21.28%)
Mutual labels:  nestjs
buscador-ao
Ponto de obtenção de informações públicas de Angola
Stars: ✭ 21 (-55.32%)
Mutual labels:  nestjs
WebApiClient.Extensions
WebApiClient项目的第三方扩展:Autofac、DependencyInjection、HttpClientFactory、SteeltoeOSS.Discovery、MessagePack、Protobuf、Json-Rpc
Stars: ✭ 73 (+55.32%)
Mutual labels:  json-rpc
nestjs-storage
Nestjs file system / file storage module wrapping flydrive
Stars: ✭ 92 (+95.74%)
Mutual labels:  nestjs
nest-js-products-api
Hexagonal architecture using nestjs
Stars: ✭ 63 (+34.04%)
Mutual labels:  nestjs
transmission
Go wrapper for the transmission API
Stars: ✭ 34 (-27.66%)
Mutual labels:  json-rpc
eth-graphql
🧠 Ethereum GraphQL API
Stars: ✭ 18 (-61.7%)
Mutual labels:  json-rpc
monorepify
A boilerplate for monorepo architecture using frameworks.
Stars: ✭ 37 (-21.28%)
Mutual labels:  nestjs
prime-nestjs
A production-ready NestJS boilerplate using Typescript, Postgres, TypeORM, and Docker.
Stars: ✭ 140 (+197.87%)
Mutual labels:  nestjs
uni-pushy-server
upushy 热更新后端。https://upushy.yoouu.cn/
Stars: ✭ 30 (-36.17%)
Mutual labels:  nestjs
nestjs-objection
Objection module for NestJS
Stars: ✭ 24 (-48.94%)
Mutual labels:  nestjs
nestjs-pdf
Nest js pdf generator
Stars: ✭ 55 (+17.02%)
Mutual labels:  nestjs
eslint-config-galex
hopefully the last eslint config you'll ever need - customizable & modern best practices for JS, TS, Node, React, Remix, Next, Jest, testing-library & storybook
Stars: ✭ 166 (+253.19%)
Mutual labels:  nestjs
nestjs-zero-to-hero
Coding through the course: NestJS Zero to Hero - Modern TypeScript Backend Development
Stars: ✭ 23 (-51.06%)
Mutual labels:  nestjs
nest-queue
The queue package for your NestJS Applications
Stars: ✭ 35 (-25.53%)
Mutual labels:  nestjs
nestjs-telegraf
🤖 Powerful Nest module for easy and fast creation Telegram bots
Stars: ✭ 300 (+538.3%)
Mutual labels:  nestjs
nestjs-boilerplate-microservice
Nestjs Microservice boilerplate: apply DDD, CQRS, and Event Sourcing within an event driven architecture
Stars: ✭ 270 (+474.47%)
Mutual labels:  nestjs
jr
A tiny Command Line Interface JavaScript Object Notation Remote Procedure Call client
Stars: ✭ 16 (-65.96%)
Mutual labels:  json-rpc
mqtt-json-rpc
JSON-RPC protocol over MQTT communication
Stars: ✭ 31 (-34.04%)
Mutual labels:  json-rpc

NestJS JSON RPC package - nestjs-json-rpc npm package

Build

Implemented JSON RPC specification

Contents

Install

npm i --save @jashkasoft/nestjs-json-rpc

Import module

Import module RpcModule from @jashkasoft/nestjs-json-rpc, example

        JsonRpcModule.forRoot({
            path: '/rpc', // path to RPC
        })

How to use simple handler

Create simple RPC handler

Create handler

create RPC handler

import { RpcId, RpcPayload, RpcVersion, RpcMethod, IRpcHandler, RpcHandler } from '@jashkasoft/nestjs-json-rpc';

@RpcHandler({
    method: 'test',
})
export class TestHandler implements IRpcHandler<Payload> {
    public async invoke(
        @RpcPayload() payload: Payload,
        @RpcVersion() version: string,
        @RpcId() id: number | string,
        @RpcMethod() method: string
    ) {
        return payload;
    }
}

Add to providers

Add TestHandler to providers array

Test with cURL

Every request to RPC is POST method and response status = 200

Test with curl

curl -X POST "http://localhost:3000/rpc" -H "accept: application/json" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "test", "id": 2}'

How to use multiple handlers in one class

Create multiple RPC handler in one class

Create handlers

Create RPC class handler

import { RpcId, RpcPayload, RpcVersion, RpcMethod, RpcMethodHandler, RpcHandler } from '@jashkasoft/nestjs-json-rpc';

@RpcHandler({
    method: 'contact',
})
export class ContactHandler {
    @RpcMethodHandler('add')
    public async add(
        @RpcPayload() payload: Payload,
        @RpcVersion() version: string,
        @RpcId() id: number | string,
        @RpcMethod() method: string
    ) {
        return payload;
    }
    
    @RpcMethodHandler('delete')
    public async delete(
        @RpcPayload() payload: Payload,
        @RpcVersion() version: string,
        @RpcId() id: number | string,
        @RpcMethod() method: string
    ) {
        return payload;
    }
}

Add to providers

Add ContactHandler to providers array

Test with cURL

Every request to RPC is POST method and response status = 200

Test with curl contact.add

curl -X POST "http://localhost:3000/rpc" -H "accept: application/json" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "contact.add", "id": 2}'

Test with curl contact.delete

curl -X POST "http://localhost:3000/rpc" -H "accept: application/json" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "contact.delete", "id": 2}'

Decorators description

field decorator description required other
params @RpcPayload() get payload ( params ) false use pipes...
jsonrpc @RpcVersion() get rpc version true use pipes...
method @RpcMethod() get rpc version true use pipes...
id @RpcId() get client operation id false if not send - response not send, RPC notification. use pipes...

Samples

See examples in samples folder

Changelog:

7.6.0

  • NestJS 7.3.* ( breaking change )
  • typescript 3.9.7 ( breaking change )
  • use DiscoveryModule

7.5.0

  • add multiple RPC handlers for class
  • NestJS 7.2.*

7.4.0

  • fix types for JsonRpcModule async options
  • export JSON_RPC_OPTIONS.
    You can inject rpc config:
    @Inject(JSON_RPC_OPTIONS) private config: JsonRpcConfig

7.3.2

  • decrease bundle size

7.3.0

  • allow response object
  • add custom headers

7.2.0

  • add injection scopes ( REQUEST / TRANSIENT ) to JSON RPC handlers
  • add logging register handlers
  • add injection scopes sample

7.1.1

  • add express engine example

7.1.0

  • add support fastify adapter

7.0.0

  • support nestjs 7.0.0
  • fix types
  • add to decorators ExecutionContext ( breaking change )
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].