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

@ws-rpc/client

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ws-rpc/client

Simple, small rfc-correct JSON-RPC 2.0 implementation with encoders support

latest
npmnpm
Version
0.0.30
Version published
Maintainers
1
Created
Source

ws-rpc

*Simple, small rfc-correct JSON-RPC 2.0 implementation with encoders support

Usage

Server

import {Server} from '@ws-rpc/server'
import {MsgpackEncoder} from '@ws-rpc/encoder-msgpack'

// see ws lib options
let wss = new Server({
  port: 8081,
  encoders: [MsgpackEncoder], // json by default
  ctx: {db},
})

let bookUpsert = async (ctx, data) => {
  let {book, created} = await ctx.db.bookUpsert(data)
  
  if (created) {
    ctx.emit('book.created', book) // emit event to current client
    // ctx.emitAll('book.created', book) // or to all clients
  }
  
  return book
}

wss.onrpc = async (ctx, method, ...args) => {
  switch (method) {
    case 'book.upsert':
      return bookUpsert(ctx, ...args)
    default:
      ctx.throwMethodNotFound()
  }
}

wss.onevent = (name, ...args) => {
  // process event from client
}

Client

import {Client} from '@ws-rpc/client'
import {MsgpackEncoder} from '@ws-rpc/encoder-msgpack'

let wsc = await new Client({
  url: 'ws://localhost:8080',
  encoders: [MsgpackEncoder], // json by default
}).connect()

wsc.onevent = (event, ...args) => {
  // process event from server
}

let book = await wsc.rpc('book.upsert', {
  name: 'Dune',
  author: 'Franklin Patrick Herbert',
})

Keywords

rpc

FAQs

Package last updated on 24 Mar 2026

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