{"id":18821396,"url":"https://github.com/borderless/json-rpc","last_synced_at":"2025-04-14T00:32:38.044Z","repository":{"id":56541796,"uuid":"233659434","full_name":"borderless/json-rpc","owner":"borderless","description":"Tiny, type-safe JSON-RPC 2.0 implementation","archived":false,"fork":false,"pushed_at":"2023-12-12T06:33:24.000Z","size":853,"stargazers_count":20,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-18T09:38:12.768Z","etag":null,"topics":["json-rpc","typescript"],"latest_commit_sha":null,"homepage":"","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/borderless.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-01-13T18:01:12.000Z","updated_at":"2023-12-12T06:33:28.000Z","dependencies_parsed_at":"2022-08-15T20:40:19.702Z","dependency_job_id":null,"html_url":"https://github.com/borderless/json-rpc","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Fjson-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Fjson-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Fjson-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Fjson-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borderless","download_url":"https://codeload.github.com/borderless/json-rpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223612915,"owners_count":17173632,"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":["json-rpc","typescript"],"created_at":"2024-11-08T00:40:31.016Z","updated_at":"2024-11-08T00:40:31.829Z","avatar_url":"https://github.com/borderless.png","language":"TypeScript","readme":"# JSON RPC\n\n[![NPM version][npm-image]][npm-url]\n[![NPM downloads][downloads-image]][downloads-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n\n\u003e Tiny, mostly compliant [JSON-RPC 2.0](https://www.jsonrpc.org/specification) implementation.\n\nThis package intentionally doesn't implement the \"arguments\" form of request parameters. This is when the input `params` can be an object or an ordered array representing the object. Instead, you can pass _any_ JSON params over the wire.\n\n## Installation\n\n```sh\nnpm install @borderless/json-rpc --save\n```\n\n## Usage\n\nThis package makes no assumptions about the transportation layer, for client or server.\n\n### Methods\n\n```ts\ntype Methods = {\n  hello: {\n    request: {};\n    response: string;\n  };\n  echo: {\n    request: { arg: string };\n    response: string;\n  };\n};\n```\n\n### Server\n\nThe server accepts a dictionary of resolvers.\n\n```ts\nimport { createServer } from \"@borderless/json-rpc\";\n\nconst server = createServer\u003cMethods\u003e({\n  hello: (_) =\u003e \"Hello World!\",\n  echo: ({ arg }) =\u003e arg,\n});\n\nconst res = await server({\n  jsonrpc: \"2.0\",\n  id: \"test\",\n  method: \"hello\",\n}); //=\u003e { jsonrpc: \"2.0\", id: \"test\", result: \"Hello World!\" }\n```\n\n### Client\n\nThe client accepts a function to `send` the JSON-RPC request.\n\n```ts\nimport { createClient } from \"@borderless/json-rpc\";\n\nconst client = createClient(async (payload) =\u003e {\n  const res = await fetch(\"...\", {\n    method: \"POST\",\n    body: JSON.stringify(payload),\n    headers: {\n      \"Content-Type\": \"application/json\",\n    },\n  });\n\n  return res.json();\n});\n\nconst result = await client({\n  method: \"hello\",\n  params: {},\n}); //=\u003e \"Hello World!\"\n\nconst results = await client.many([\n  {\n    method: \"hello\",\n    params: {},\n  },\n  {\n    method: \"echo\",\n    params: { arg: \"Test\" },\n  },\n]); //=\u003e [\"Hello World!\", \"Test\"]\n```\n\n## License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/@borderless/json-rpc.svg?style=flat\n[npm-url]: https://npmjs.org/package/@borderless/json-rpc\n[downloads-image]: https://img.shields.io/npm/dm/@borderless/json-rpc.svg?style=flat\n[downloads-url]: https://npmjs.org/package/@borderless/json-rpc\n[travis-image]: https://img.shields.io/travis/borderless/json-rpc.svg?style=flat\n[travis-url]: https://travis-ci.org/borderless/json-rpc\n[coveralls-image]: https://img.shields.io/coveralls/borderless/json-rpc.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/borderless/json-rpc?branch=master\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborderless%2Fjson-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborderless%2Fjson-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborderless%2Fjson-rpc/lists"}