{"id":26049579,"url":"https://github.com/mahsumurebe/jrpc-client","last_synced_at":"2025-03-08T01:44:45.294Z","repository":{"id":42031855,"uuid":"249537736","full_name":"mahsumurebe/jrpc-client","owner":"mahsumurebe","description":"JSONRPC 2.0 NodeJS Client written in TypeScript","archived":false,"fork":false,"pushed_at":"2022-11-23T08:40:51.000Z","size":428,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-20T19:48:18.820Z","etag":null,"topics":["http-client","jsonrpc","jsonrpc-client","jsonrpc-lib","jsonrpc2","jsonrpc2-ws","websocket"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@mahsumurebe/jrpc-client","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mahsumurebe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-23T20:31:54.000Z","updated_at":"2023-07-27T05:48:45.000Z","dependencies_parsed_at":"2022-08-12T02:51:04.036Z","dependency_job_id":null,"html_url":"https://github.com/mahsumurebe/jrpc-client","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mahsumurebe%2Fjrpc-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mahsumurebe%2Fjrpc-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mahsumurebe%2Fjrpc-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mahsumurebe%2Fjrpc-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mahsumurebe","download_url":"https://codeload.github.com/mahsumurebe/jrpc-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242487757,"owners_count":20136651,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-client","jsonrpc","jsonrpc-client","jsonrpc-lib","jsonrpc2","jsonrpc2-ws","websocket"],"created_at":"2025-03-08T01:44:38.963Z","updated_at":"2025-03-08T01:44:43.556Z","avatar_url":"https://github.com/mahsumurebe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JRPC Client\nJSONRPC 2.0 Client package for Nodejs. Fully tested to comply with the official [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification)\n\n![GitHub package.json version](https://img.shields.io/github/package-json/v/mahsumurebe/jrpc-client?style=for-the-badge)\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/mahsumurebe/jrpc-client?style=for-the-badge)\n![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/mahsumurebe/jrpc-client?style=for-the-badge)\n![npm](https://img.shields.io/npm/dt/@mahsumurebe/jrpc-client?style=for-the-badge)\n\n![Libraries.io SourceRank, scoped npm package](https://img.shields.io/librariesio/sourcerank/npm/@mahsumurebe/jrpc-client?style=for-the-badge)\n![minzipped-size](https://img.shields.io/bundlephobia/minzip/@mahsumurebe/jrpc-client/latest?style=for-the-badge)\n![minfied-size](https://img.shields.io/bundlephobia/min/@mahsumurebe/jrpc-client/latest?style=for-the-badge)\n\n![issues-open](https://img.shields.io/github/issues/mahsumurebe/jrpc-client?style=for-the-badge)\n![issues-closed](https://img.shields.io/github/issues-closed/mahsumurebe/jrpc-client?style=for-the-badge)\n![license](https://img.shields.io/github/license/mahsumurebe/jrpc-client?style=for-the-badge)\n\n## Quick Overview  \n  It is used to quickly create JSONRPC Client. Method call is very simple.  \n\n#### To Create a Server\nYou can use the [@mahsumurebe/jrpc-server](https://www.npmjs.com/package/@mahsumurebe/jrpc-server) package to create a server.\n\n## Install  \nFor installation, you can run the following command in the directory of your project.\n```shell script\nnpm install @mahsumurebe/jrpc-client  \n```  \n\n## Usage\nIt should not create a JRPCClient instance.  \n```typescript\nimport { JRPCClient, HttpAdapter } from '@mahsumurebe/jrpc-client';\n\n// Create instance\nconst clientInstance = new JRPCClient(new HttpAdapter('http://localhost:3000'));\n// Call start method for connection\nawait clientInstance.start();\n```  \n\n### Call Method\nMethod calls are made after the JRPCClient instance is created.  \n```typescript\n// Call foo method with \"bar\" and \"baz\" parameters\nconst response = await clientInstance.call({\n  id: 1,\n  jsonrpc: \"2.0\",\n  method: \"foo\",\n  params: [\"bar\", \"baz\"],\n});\nconsole.log(response);\n// Response Object\n// { id: 1, jsonrpc: \"2.0\", response: \"foo response\" }\n```  \nThe call method returns the JSONRPC response. Returns the ErrorResponse class instance if the request response is an error.  \n\n### Batch Call Method \nCall method can be used to call requests. You can review the usage example below.  \n  \n```typescript\nconst batchResponse = await clientInstance.call([\n  { id: 1, jsonrpc: \"2.0\", method: \"foo\", params: [\"bar\", \"baz\"] },\n  { id: 2, jsonrpc: \"2.0\", method: \"bar\", params: [\"bar\", \"baz\"] },\n  { jsonrpc: \"2.0\", method: \"notification\", params: [\"bar\", \"baz\"] }, // Notification request does not return value\n]);\nconsole.log(batchResponse);\n// [\n//   { id: 1, jsonrpc: \"2.0\", response: \"foo response\" },\n//   { id: 2, jsonrpc: \"2.0\", response: \"bar response\" },\n// ]\n```\n\n### Notification Method\nCheck out the sample code below to make a method notification.\n\n```typescript\n// Notification foo method with \"bar\" and \"baz\" parameters\nawait clientInstance.notification({\n  jsonrpc: \"2.0\",\n  method: \"foo\",\n  params: [\"bar\", \"baz\"],\n});\n```  \n**Note:** The notification method does not return any response. The request is sent to the server. No response is expected from the server.\n\n### Batch Notification Method \n\nCheck out the example below for sending batch notifications.\n\n```typescript\nawait clientInstance.notification([\n  { jsonrpc: \"2.0\", method: \"foo\", params: [\"bar\", \"baz\"] },\n  { jsonrpc: \"2.0\", method: \"bar\", params: [\"bar\", \"baz\"] },\n  { jsonrpc: \"2.0\", method: \"baz\", params: [\"bar\", \"baz\"] }, \n]);\n```\n\n## Adapters\n\nThere are HTTP and Websocket adapters available.\n\n### HTTP\n\nHTTP Adapter is used to connect to JRPC Servers served over HTTP Protocol.\n\n```typescript\n// Adapter Instance\nimport {JRPCClient, HttpAdapter} from '@mahsumurebe/jrpc-client';\n\nconst adapter = new HttpAdapter('http://localhost:3000');\n\n// Client Instance\nconst clientInstance = new JRPCClient(adapter);\n```\n\n#### Configuration List\nConfigurations are defined in the object in the first parameter of the construction method when creating the HttpAdapter.\n\n| KEY     | DEFAULT   | DESCRIPTION     | Type     |\n|---------|-----------|-----------------|----------|\n| parser  | null      | Response parser | Function |\n| headers | null      | HTTP Headers    | object   |\n| timeout | 10_000    | Timeout         | number   |\n\n\n### Websocket\n\nWebsocket Adapter is used to connect to JRPC Servers served over Websocket Protocol.\n\n```typescript\n// Adapter Instance\nimport { JRPCClient, WebsocketAdapter } from '@mahsumurebe/jrpc-client';\n\nconst adapter = new WebsocketAdapter('ws:/localhost:3000');\n\n// Client Instance\nconst clientInstance = new JRPCClient(adapter);\n```\n\n#### Configuration List\nConfigurations are defined in the object in the first parameter of the construction method when creating the WebsocketAdapter.\n\n| KEY     | DEFAULT   | DESCRIPTION     | Type     |\n|---------|-----------|-----------------|----------|\n| parser  | null      | Response parser | Function |\n| headers | null      | HTTP Headers    | object   |\n| timeout | 10_000    | Timeout         | number   |\n\n#### Custom Adapters\n\nFor custom adapters, you need to extend the adapter class with the `AdapterAbstract` abstract class.\nYou have to create the abstract functions request, connect and destroy inside the class.\n\n**connect**: A piece of code that provides the protocol connection should be added to this method.\n\n**destroy**: A piece of code that breaks the protocol connection should be added to this method.\n\n**request**: A piece of code that sends the body to the server and parses the output should be added to this method.\n_When there is a response from the server, the response object should be sent to the `adapter.config.parse` function._\n\n## Resources\n\n - [Changelog](https://github.com/mahsumurebe/jrpc-client/blob/development/CHANGELOG.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahsumurebe%2Fjrpc-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmahsumurebe%2Fjrpc-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahsumurebe%2Fjrpc-client/lists"}