{"id":27899225,"url":"https://github.com/chord-ts/rpc","last_synced_at":"2025-05-05T19:23:56.992Z","repository":{"id":208522655,"uuid":"721845229","full_name":"chord-ts/rpc","owner":"chord-ts","description":"💎 Cutting edge transport framework vanishing borders between frontend and backend","archived":false,"fork":false,"pushed_at":"2025-03-17T12:40:31.000Z","size":2021,"stargazers_count":53,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-05T19:23:51.064Z","etag":null,"topics":["chord","express","http","json-rpc","json-rpc-transport","rpc","sveltekit","typescript"],"latest_commit_sha":null,"homepage":"https://chord.vercel.app/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chord-ts.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-21T22:22:48.000Z","updated_at":"2025-04-11T08:00:07.000Z","dependencies_parsed_at":"2024-01-17T22:11:21.497Z","dependency_job_id":"1721837c-7b01-4dc3-b27d-dac0fa4fb1e5","html_url":"https://github.com/chord-ts/rpc","commit_stats":null,"previous_names":["dmdin/chord","chord-ts/rpc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chord-ts%2Frpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chord-ts%2Frpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chord-ts%2Frpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chord-ts%2Frpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chord-ts","download_url":"https://codeload.github.com/chord-ts/rpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252561247,"owners_count":21768090,"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":["chord","express","http","json-rpc","json-rpc-transport","rpc","sveltekit","typescript"],"created_at":"2025-05-05T19:23:56.566Z","updated_at":"2025-05-05T19:23:56.984Z","avatar_url":"https://github.com/chord-ts.png","language":"TypeScript","readme":"\u003cdiv id=\"header\" align=\"center\"\u003e\n\u003cimg src=\"./docs/public/strings.png\" alt=\"Strings\"/\u003e\n\n# Chord - RPC Framework\n\nThe revolution in the world of client-server communication. Type-safe RPC on top of [JSON-RPC v2](https://www.jsonrpc.org/specification) protocol.\n\n\u003ca href=\"https://www.typescriptlang.org/\"\u003e\u003cimg src=\"https://img.shields.io/badge/TypeScript-3178c6?style=for-the-badge\u0026logo=typescript\u0026logoColor=white\"\u003e\u003c/a\u003e\n\u003ca href=\"https://kit.svelte.dev/\"\u003e\u003cimg src=\"https://img.shields.io/badge/SvelteKit-191919?style=for-the-badge\u0026logo=svelte\u0026logoColor=FF3E00\"\u003e\u003c/a\u003e\n\u003ca href=\"https://expressjs.com/\"\u003e\u003cimg src=\"https://img.shields.io/badge/Express-69b74d?style=for-the-badge\u0026logo=express\u0026logoColor=white\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.jsonrpc.org/specification\"\u003e\u003cimg src=\"https://img.shields.io/badge/JSONRPC-18181a?style=for-the-badge\u0026logo=json\u0026logoColor=white\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"download stats\" src=\"https://img.shields.io/npm/dm/@chord-ts/rpc?style=flat\u0026color=218380\"\u003e  \n  \u003cimg alt=\"version\" src=\"https://img.shields.io/npm/v/@chord-ts/rpc?style=flat\u0026color=3F4CF8\u0026label=latest\"\u003e\n  \u003cimg alt=\"license\" src=\"https://img.shields.io/npm/l/@chord-ts/rpc?color=D81159\"\u003e\n  \u003cimg alt=\"maintainability\" src=\"https://img.shields.io/codeclimate/maintainability/chord-ts/rpc?color=04E762\"\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n\u003cimg alt=\"Repository Stats\" src=\"https://repobeats.axiom.co/api/embed/64b5982f552f7d4a6b4abfc52c3251b8591f2da8.svg\"\u003e\n\n## ✅ Used inside\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://sbermarketing.ru\"\u003e\n  \u003cimg alt=\"SberMarketing\" src=\"./docs/public/SBER_MARKETING_LOGO.png\" alt=\"SberMarketing\" width=\"200\"/\u003e\n  \u003c/a\u003e  \n\u003c/div\u003e\n\n## 🥏 Why?\n\nBecause client-server communication becomes complex with the growth of project. Hundreds of __REST API__ endpoints destroy [Developer Experience](https://github.blog/2023-06-08-developer-experience-what-is-it-and-why-should-you-care/). On the other hand [GraphQL](https://graphql.org/) seems like a cumbersome and suboptimal solution, and [gRPC](https://grpc.io/) works only for server-to-server\n\nThat's where __Chord__ comes to solve accumulated problems of modern software development\n\n## ✨ Features\n\n* Protocol agnostic\n* Framework agnostic\n* Type safe exchange\n* Accelerated development\n* IDE hinting out-of-box\n* Client size ~1.5kb\n\n## ⚙️ Installation\n\n**Chord** can be used with any backend library. Install it freely from [npm](https://www.npmjs.com/package/@chord-ts/rpc) via your favorite package manager\n\n```bash\nnpm install @chord-ts/rpc\n# or\npnpm install @chord-ts/rpc\n```\n\n**Chord** uses [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) and [reflection](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect) under the hood, to construct server and client\n\nSo you need to configure your _tsconfig.json_ first\n\n**`./tsconfig.json`**\n\n```json5\n{\n  compilerOptions: {\n    // Other stuff...\n\n    target: 'ESNext',\n    experimentalDecorators: true,\n    emitDecoratorMetadata: true\n  }\n}\n```\n\n### ⚠️ Caveats\n\nIf you are using [Vite](https://vitejs.dev/) as bundler of your project, you have to note, that [ESbuild](https://esbuild.github.io/) that is used under the hood, [does not support](https://github.com/evanw/esbuild/issues/257) _emitDecoratorMetadata_ flag at the moment\n\nThus, you have to use additional plugins for [Vite](https://vitejs.dev/). I personally recommend to try out [SWC](https://www.npmjs.com/package/unplugin-swc). It fixes this issue and doesn't impact on rebuilding performance\n\nThen add [SWC](https://www.npmjs.com/package/unplugin-swc) plugin to [Vite](https://vitejs.dev/):\n\n**`./vite.config.ts`**\n\n```javascript\nimport { sveltekit } from '@sveltejs/kit/vite';\nimport { defineConfig } from 'vitest/config';\nimport swc from 'unplugin-swc';\n\nexport default defineConfig({\n  plugins: [sveltekit(), swc.vite()],\n  test: {\n    include: ['src/**/*.{test,spec}.{js,ts}']\n  }\n});\n```\n\n## 🛠️ Usage\n\nThe example below uses [SvelteKit](https://kit.svelte.dev/) framework, but you can try your own on any other preferred framework like [Next](https://nextjs.org/) or [Nuxt](https://nuxt.com/)\n\n### 📝 Implement the Class\n\nThen implement defined interface inside your controller. In [SvelteKit](https://kit.svelte.dev/) it's [+server.ts](https://kit.svelte.dev/docs/routing#server) file\n\n**`./src/routes/+server.ts`**\n\n```typescript\nimport { json } from '@sveltejs/kit';\nimport { Composer, rpc, type Composed } from '@chord-ts/rpc'; // Main components of Chord we will use\nimport { sveltekitMiddleware } from '@chord-ts/rpc/middlewares'; // Middleware to process RequestEvent object\n\n// 1. Implement the class containing RPC methods\nexport class Say {\n  @rpc() // Use decorator to register callable method\n  hello(name: string): string {\n    return `Hello, ${name}!`;\n  }\n}\n\n// 2. Init Composer instance that will handle requests\nexport const composer = Composer.init({ Say: new Say() });\n\n// 3. Create a type that will be used on frontend\nexport type Client = typeof composer.clientType;\n\ncomposer.use(sveltekitMiddleware()); // Use middleware to process SvelteKit RequestEvent\n\n// 4. SvelteKit syntax to define POST endpoint\nexport async function POST(event) {\n  // Execute request in place and return result of execution\n  return json(await composer.exec(event));\n}\n```\n\nWhat we did in this listing is defined everything we need to handle requests. The first three steps are the same for any framework you will use, while the fourth is depended of it\n\nYou can implement a middleware for your backend framework which must extract body of request\n\n### 🖼️ Use RPC on frontend\n\nNow we are ready to call the method on frontend. As we use [SvelteKit](https://kit.svelte.dev/), we have a full power of [Svelte](https://svelte.dev/) for our UI\n\n**`./src/routes/+page.svelte`**\n\n```html\n\u003cscript lang=\"ts\"\u003e\n  import { client } from '@chord-ts/rpc/client';\n  import { onMount } from 'svelte';\n\n  // Import our Contract\n  import type { Client } from './+server';\n\n  // Init dynamic client with type checking\n  // Use Contract as Generic to get type safety and hints from IDE\n  // dynamicClient means that RPC will be created during code execution\n  // and executed when the function call statement is found\n  const rpc = client\u003cClient\u003e({ endpoint: '/' });\n\n  let res;\n  // Called after Page mount. The same as useEffect(..., [])\n  onMount(async () =\u003e {\n    // Call method defined on backend with type-hinting\n    res = await rpc.Say.hello('world');\n    console.log(res);\n  });\n\u003c/script\u003e\n\n\u003ch1\u003eChord call Test\u003c/h1\u003e\n\u003cp\u003eResult: {res}\u003c/p\u003e\n```\n\n## 📦 Try it yourself\n\nReady to run sandbox with prepared environment for your experiments\n\n\u003ca href=\"https://www.sveltelab.dev/rkt1wa1z8trbcuc?files=.%2Fsrc%2Froutes%2F%2Bpage.svelte%2C.%2Fsrc%2Froutes%2F%2Bserver.ts\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/SvelteLab-191919?style=for-the-badge\u0026logo=svelte\u0026logoColor=FF3E00\"\u003e\u003c/a\u003e\n\n## 📚 Further reading\n\nWe have finished a basic example of using **Chord**. But it's the tip of the iceberg of possibilities that framework unlocks\n\n---\n\nVisit the [Documentation](https://chord.vercel.app)(Coming Soon) to dive deeper\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchord-ts%2Frpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchord-ts%2Frpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchord-ts%2Frpc/lists"}