{"id":48259,"library":"json-rpc-ws","title":"json-rpc-ws","description":"A WebSocket transport library for JSON-RPC that enables asynchronous bidirectional requests and responses over WebSocket connections. Version 7.0.1 supports Node.js and browser environments via separate entry points. It provides a simple API with server and client creation, method exposure, and callback-based request/response handling. Key differentiators: uses the popular 'ws' library for Node, supports both server and client in one package, and offers a lightweight abstraction over raw WebSocket messaging.","status":"active","version":"7.0.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/andyet/json-rpc-ws","tags":["javascript","json-rpc","websocket"],"install":[{"cmd":"npm install json-rpc-ws","lang":"bash","label":"npm"},{"cmd":"yarn add json-rpc-ws","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-rpc-ws","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core WebSocket library used for Node.js server and client. Browser builds use the native WebSocket API.","package":"ws","optional":false}],"imports":[{"note":"In Node.js, CJS require() works but ESM import * is recommended. For browser, use 'json-rpc-ws/browser'.","wrong":"const JsonRpcWs = require('json-rpc-ws')","symbol":"default (the module itself)","correct":"import * as JsonRpcWs from 'json-rpc-ws'"},{"note":"createServer() is the factory, not a constructor.","wrong":"const server = new JsonRpcWs.Server()","symbol":"server instance","correct":"const server = JsonRpcWs.createServer()"},{"note":"createClient() is the factory, not a constructor.","wrong":"const client = new JsonRpcWs.Client()","symbol":"client instance","correct":"const client = JsonRpcWs.createClient()"}],"quickstart":{"code":"const JsonRpcWs = require('json-rpc-ws');\n\n// Create server\nconst server = JsonRpcWs.createServer();\n\n// Expose a method\nserver.expose('hello', function (params, reply) {\n    reply(null, { greeting: 'Hello, ' + params[0] });\n});\n\n// Start server\nserver.start({ port: 8080 }, function () {\n    console.log('Server started');\n});\n\n// In a separate client script:\n// const client = JsonRpcWs.createClient();\n// client.connect('ws://localhost:8080', function () {\n//     client.send('hello', ['World'], function (err, reply) {\n//         console.log(reply); // { greeting: 'Hello, World' }\n//     });\n// });","lang":"javascript","description":"Shows server creation, method exposure, and callbacks for request/response over WebSocket."},"warnings":[{"fix":"import { ... } from 'json-rpc-ws/browser' in browser environments.","message":"ws library versions >=1.0.0 removed client code for browsers; use the browser entry point 'json-rpc-ws/browser'.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install 'ws' alongside: npm install ws json-rpc-ws","message":"The 'ws' library is a peer dependency; ensure compatibility with your project's ws version.","severity":"deprecated","affected_versions":"all"},{"fix":"Always call reply exactly once with either error or reply as non-null, not both.","message":"Method handlers can only have one reply per request; sending multiple replies or non-null both error and reply will cause issues.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'7.0.1':24 'abstract':73 'api':38 'asynchron':15 'base':49 'bidirect':16 'browser':28 'callback':48 'callback-bas':47 'client':42,65 'connect':22 'creation':43 'differenti':53 'enabl':14 'entri':32 'environ':29 'exposur':45 'handl':51 'javascript':78 'json':2,11,80 'json-rpc':10,79 'json-rpc-w':1 'key':52 'librari':8,58 'lightweight':72 'messag':77 'method':44 'node':60 'node.js':26 'offer':70 'one':67 'packag':68 'point':33 'popular':56 'provid':35 'raw':75 'request':17 'request/response':50 'respons':19 'rpc':3,12,81 'separ':31 'server':40,63 'simpl':37 'support':25,61 'transport':7 'use':54 'version':23 'via':30 'websocket':6,21,76,82 'ws':4,57","created_at":"2026-06-07T16:55:42.884651+00:00","updated_at":"2026-06-07T16:55:42.884651+00:00","problems":[{"fix":"npm install ws","cause":"Missing peer dependency ws.","error":"Cannot find module 'ws'"},{"fix":"Use 'json-rpc-ws/browser' in browser code.","cause":"Using Node-appropriate import in browser (e.g., 'json-rpc-ws' instead of 'json-rpc-ws/browser').","error":"Uncaught ReferenceError: WebSocket is not defined"},{"fix":"Use a different method name or remove the existing handler first.","cause":"Attempting to expose a method that already has a handler.","error":"handler already exposed: methodName"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/andyet/json-rpc-ws#readme","github":"ssh://git@github.com/andyet/json-rpc-ws","docs":null,"changelog":null,"pypi":null,"npm":"json-rpc-ws","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}