{"id":21999068,"url":"https://github.com/ptol/typed-json-rpc","last_synced_at":"2025-06-19T16:37:12.508Z","repository":{"id":65522486,"uuid":"485044642","full_name":"ptol/typed-json-rpc","owner":"ptol","description":"Simple, statically typed and ergonomic way to do async communications (events, workers, http requests) with json-rpc","archived":false,"fork":false,"pushed_at":"2022-08-30T09:55:30.000Z","size":115,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-01T12:13:54.648Z","etag":null,"topics":["json-rpc","web-workers"],"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/ptol.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":"2022-04-24T14:07:34.000Z","updated_at":"2023-12-09T11:47:38.000Z","dependencies_parsed_at":"2023-01-27T05:45:40.721Z","dependency_job_id":null,"html_url":"https://github.com/ptol/typed-json-rpc","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ptol/typed-json-rpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptol%2Ftyped-json-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptol%2Ftyped-json-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptol%2Ftyped-json-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptol%2Ftyped-json-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ptol","download_url":"https://codeload.github.com/ptol/typed-json-rpc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptol%2Ftyped-json-rpc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260788012,"owners_count":23063251,"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","web-workers"],"created_at":"2024-11-29T22:27:34.343Z","updated_at":"2025-06-19T16:37:07.498Z","avatar_url":"https://github.com/ptol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typed-json-rpc\n\n\u003eSimple, statically typed and ergonomic way to do async communications (events, workers, http requests) with json-rpc \n\n## Install\n\n```bash\nnpm install typed-json-rpc\n```\n\n## Describe your API\n\n```typescript\nexport interface Api {\n  sum: (x: number, y: number) =\u003e number\n  increase: (x: number) =\u003e number\n}\n```\n\n## Create your API implementation as request handler\n\n```typescript\nconst requestHandler = createRequestHandler\u003cApi\u003e({\n  increase: (x) =\u003e {\n    return x + 1\n  },\n  sum: (x, y) =\u003e x + y,\n})\n```\n\n## Create a client\n```typescript\nconst sender = createHttpSender()\nconst client = createJsonRpcClient\u003cApi\u003e(sender)\n```\n\n## And call your API\n```typescript\nconst x = await client.increase(100)\nconst y = await client.sum(1,2)\n```\n\n\u003e All this code can be used for any type of async communication. The difference is how you send your requests and responses.\n \n## Http sender example\n```typescript\nexport const createHttpSender = (url: string): RequestSender =\u003e ({\n  sendRequest(request: JsonRpcRequest) {\n    return axios\n      .post\u003cJsonRpcResponse, AxiosResponse\u003cJsonRpcResponse\u003e\u003e(\n        url,\n        request,\n      ).then((x) =\u003e\n        'error' in x.data ? Promise.reject(x.data.error) : x.data.result,\n      )\n  },\n})\n```\n\n## Express responses\n\n```typescript\napp.post('/', async (req, res) =\u003e {\n  const response = await requestHandler.handleRequest(req.body)\n  return res.status(200).json(response)\n})\n\n```\n\n## [Full http example](https://github.com/ptol/typed-json-rpc/tree/main/examples/src/http)\n\n## Worker and EventEmitter examples\n\n* [Worker example](https://github.com/ptol/typed-json-rpc/tree/main/examples/src/worker)\n* [EventEmitter example](https://github.com/ptol/typed-json-rpc/tree/main/examples/src/events)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptol%2Ftyped-json-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fptol%2Ftyped-json-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptol%2Ftyped-json-rpc/lists"}