{"id":13998503,"url":"https://github.com/fabiospampinato/picorpc","last_synced_at":"2025-07-27T16:31:38.457Z","repository":{"id":65967021,"uuid":"603635735","full_name":"fabiospampinato/picorpc","owner":"fabiospampinato","description":"A tiny RPC library and spec, inspired by JSON-RPC 2.0 and tRPC.","archived":false,"fork":false,"pushed_at":"2024-01-07T17:46:05.000Z","size":25,"stargazers_count":94,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-30T00:33:45.627Z","etag":null,"topics":["json","pico","rpc","tiny","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/fabiospampinato.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-02-19T05:27:44.000Z","updated_at":"2024-07-25T01:05:11.000Z","dependencies_parsed_at":"2024-01-07T18:43:28.279Z","dependency_job_id":null,"html_url":"https://github.com/fabiospampinato/picorpc","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fpicorpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fpicorpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fpicorpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fpicorpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabiospampinato","download_url":"https://codeload.github.com/fabiospampinato/picorpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227817017,"owners_count":17824200,"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","pico","rpc","tiny","typescript"],"created_at":"2024-08-09T19:01:43.642Z","updated_at":"2024-12-02T23:16:08.060Z","avatar_url":"https://github.com/fabiospampinato.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# PicoRPC\n\nA tiny RPC library and [spec](./spec.md), inspired by [JSON-RPC 2.0](https://www.jsonrpc.org/specification) and [tRPC](https://trpc.io).\n\n## Install\n\n```sh\nnpm install --save picorpc\n```\n\n## Usage\n\n```ts\nimport {createAbstractClient, createAbstractServer} from 'picorpc';\nimport {createMemoryClient, createMemoryServer} from 'picorpc';\nimport {createHttpClient, createHttpServer} from 'picorpc';\n\n// Custom map of procedures to expose to the client\n\nconst Procedures = {\n  ctx () { // This procedure reads something from the context, which will be attached to \"this\"\n    return this.value;\n  },\n  sum ( a, b ) { // This procedure is a simple pure function that doesn't use the context\n    return a + b;\n  },\n  throw () { // This procedure throws, with a custom error code and data value\n    const error = new Error ( 'Some custom error' );\n    error.code = 1;\n    error.data = 'Some data';\n    throw error;\n  }\n};\n\n// Create an in-memory client/server\n// An in-memory server behind a proper HTTP server is the recommended way to expose procedures via an API\n// An in-memory client is mostly useful for testing\n\nconst server = createMemoryServer ({\n  procedures: Procedures\n});\n\nconst client = createMemoryClient ({\n  server, // The in-memory server to pass requests to\n  context: () =\u003e ({ // Custom, optional, context object, which will be attached to every request automatically\n    value: 123\n  })\n});\n\nawait client.sum ( 1, 2 ); // =\u003e 3\nawait client.ctx (); // =\u003e 123\nawait client.throw (); // =\u003e This will throw\n\n// Create an HTTP client/server\n// The HTTP server is intended for simple internal inter-process communication\n// The HTTP client makes request with the fetch API, so it works everywhere\n\nconst client = createHttpClient ({\n  context: () =\u003e ({ // Custom, optional, context object, which will be attached to every request automatically\n    value: 123\n  }),\n  serializer: JSON.stringify, // Custom, optional, serializer\n  deserializer: JSON.parse, // Custom, optional, deserializer\n  url: 'http://localhost:6000' // Required endpoint URL\n});\n\nconst server = createHttpServer ({\n  serializer: JSON.stringify, // Custom, optional, serializer\n  deserializer: JSON.parse, // Custom, optional, deserializer\n  port: 6000, // The port to start listening at\n  procedures: Procedures\n});\n\nawait client.sum ( 1, 2 ); // =\u003e 3\nawait client.ctx (); // =\u003e 123\nawait client.throw (); // =\u003e This will throw\n\nserver.close (); // Close the server, stopping listening\n\n// Create an abstract server, to use your own transport protocol\n\nconst client = createAbstractClient ({\n  handler: request =\u003e {\n    //TODO: Send the request somewhere and read the result back\n  }\n});\n\nconst client = createAbstractServer ({\n  procedures: Procedures,\n  handler: response =\u003e {\n    //TODO: Do something with the response object, optionally\n  }\n});\n```\n\n## License\n\nMIT © Fabio Spampinato\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiospampinato%2Fpicorpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabiospampinato%2Fpicorpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiospampinato%2Fpicorpc/lists"}