{"id":18052780,"url":"https://github.com/akash-joshi/rocketrpc","last_synced_at":"2025-04-05T00:09:15.645Z","repository":{"id":45629577,"uuid":"346610325","full_name":"akash-joshi/rocketrpc","owner":"akash-joshi","description":"A typesafe framework to destroy client-server barriers.","archived":false,"fork":false,"pushed_at":"2024-12-11T08:18:11.000Z","size":10744,"stargazers_count":162,"open_issues_count":0,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-03T02:02:07.726Z","etag":null,"topics":["frontend","javascript","nodejs","promise","rpc","typesafe","typescript","typescript-generics","websockets"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/rocketrpc","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akash-joshi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"akash-joshi"}},"created_at":"2021-03-11T07:09:16.000Z","updated_at":"2025-03-29T19:33:39.000Z","dependencies_parsed_at":"2024-02-04T12:40:46.383Z","dependency_job_id":"d40bda7c-3b8d-42fe-9538-dc6d3dfabe44","html_url":"https://github.com/akash-joshi/rocketrpc","commit_stats":{"total_commits":71,"total_committers":4,"mean_commits":17.75,"dds":0.323943661971831,"last_synced_commit":"70b35c8d0d35c84ffdb3f360612bf95d5f6da642"},"previous_names":["akash-joshi/functions-over-websockets"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akash-joshi%2Frocketrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akash-joshi%2Frocketrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akash-joshi%2Frocketrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akash-joshi%2Frocketrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akash-joshi","download_url":"https://codeload.github.com/akash-joshi/rocketrpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266564,"owners_count":20910836,"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":["frontend","javascript","nodejs","promise","rpc","typesafe","typescript","typescript-generics","websockets"],"created_at":"2024-10-30T23:13:09.603Z","updated_at":"2025-04-05T00:09:15.628Z","avatar_url":"https://github.com/akash-joshi.png","language":"TypeScript","readme":"# RocketRPC 🚀 - A fast and secure RPC to expose server data to a client.\n\n![Frame 8175 (1)](https://user-images.githubusercontent.com/22196279/219864833-74471e79-8afe-446a-95f6-7d37ef007e97.png)\n\nRocketRPC is typesafe RPC library which gets out of your way. Define methods in your server, which you can access instantly in your client - complete with auto-completions and type-checking.\n\n## Usage\n\nhttps://user-images.githubusercontent.com/22196279/218526614-2b971301-0a72-4092-88d0-e47a8f29e3b6.mp4\n\n## Talk\n\nClick on the image below to watch @akash-joshi talk about RocketRPC at Svelte London:\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://youtu.be/RkQ_f7XxdMI?t=2632\"\u003e\n    \u003cimg alt=\"Talk\" src=\"https://user-images.githubusercontent.com/22196279/226218558-f7a325a2-a051-4f06-9bc5-089051f1a48f.jpg\" height=\"350\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n### Installation\n\nInstall the package\n\n```sh\nnpm i rocketrpc\n```\n\n### Client\n\n\u003e Note: On the client side, all functions return a Promise with the result by default, because of the asynchronous nature of sockets. So, all passed functions are also modified to return a Promise.\n\n```ts\nimport { Client } from \"rocketrpc\";\nimport { API } from \"../server\";\n\nconst client = Client\u003cAPI\u003e(\"http://localhost:8080\");\n\nconst { listFiles, prisma } = client;\n\nconst main = async () =\u003e {\n  // use prisma on the client\n  console.log(await prisma.user.findMany());\n\n  // passing multiple parameters to the function\n  console.log(await client.sum(12, 20));\n\n  // get server details\n  console.log(await listFiles());\n};\n\nmain();\n```\n\n### Server\n\n```ts\nimport { Server } from \"rocketrpc\";\nimport { PrismaClient } from \"@prisma/client\";\n\nimport listFiles from \"./apis/listFiles\";\n\nconst api = {\n  // initialize Prisma once\n  prisma: new PrismaClient();\n\n  sum: (x: number, y: number) =\u003e x + y,\n\n  // Fetch all files on server\n  listFiles,\n};\n\nexport type API = typeof api;\n\nServer(8080, api);\n```\n\n## Error Handling\n\nAt the moment, any error on the server-side is sent to `std:error` and thrown on the client side.\n\nTry running the examples locally!\n\n## Metadata Context\n\n### Socket Client\n\nThe socket.io client being used by rocketRPC is accessible via the `_rocketRpcContext` key.\n\n## How does it work internally?\n\nIn short, the library depends on Websockets, Object Proxies, and Typescript generics to work. In detail:\n\n### 1. Websockets\n\nWe use socket.io for fast and reliable socket connections. Websockets can be lighter than HTTP requests when a large number of connections are needed. Also, they have a smaller code footprint than HTTP requests. Their usage is anyways abstracted away in the codebase, and they can be replaced with any other technology if needed.\n\n### 2. Object Proxies\n\nThe framework utilizes Object Proxies get control over the client object. Any function call made on a property of the client object (or on a deconstructed property), like\n\n```ts\nclient.functionOne();\n\n// or\n\nconst { functionOne } = client;\nfunctionOne();\n```\n\nis handled by a `get` property which has been set on the Object Proxy [here](https://github.com/akash-joshi/functions-without-borders/blob/45ed7558845b6dbf03fc368b96ca175262956051/src/client/index.ts#L33).\n\nYou can go through the code to see how it uses the property name and parameters to make a socket call to the server.\n\n### 3. Typescript Generics\n\nAll of the auto-complete goodness that the framework provides throughout the app depends on Typescript generics. On the server side, the type is directly applied on the API object,\n\n```ts\nconst api: API = { ...yourApi };\n```\n\nwhile on the client side it's passed to the `Client` initializer.\n\n```ts\nconst client = Client\u003cAPI\u003e(endpoint);\n```\n\nThe client function is actually a generic, which accepts the type provided by the user and applies `Promise` to the return type of each of them. It's a very Typescript-specific piece of code but you can read it [here](https://github.com/akash-joshi/functions-without-borders/blob/01553873cd1a1f1acc66270c5521a74b58680be0/src/client/index.ts#L3).\n\n## Sponsors\n\nIf you find RocketRPC enjoyable to work with and wish to show your support for the project, you can express your gratitude by sponsoring it through [GitHub Sponsors](https://github.com/sponsors/akash-joshi)!\n\nFurthermore, if your company is currently utilizing RocketRPC and would like to support its long-term maintenance, please refer to the [sponsorship tiers](https://github.com/sponsors/akash-joshi).\n\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003ctd align=\"center\"\u003e\u003ca href=\"https://rocketconnect.co.uk/?ref=rocketrpc\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/96782953?v=4\u0026s=200\" width=\"200\" alt=\"RocketConnect\"/\u003e\u003cbr /\u003eRocketConnect\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Contributing\n\nPull requests are welcome. You'll probably find lots of improvements to be made.\n\nOpen issues for feedback, requesting features, reporting bugs or discussing ideas.\n","funding_links":["https://github.com/sponsors/akash-joshi","https://github.com/sponsors/akash-joshi)!"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakash-joshi%2Frocketrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakash-joshi%2Frocketrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakash-joshi%2Frocketrpc/lists"}