{"id":19411098,"url":"https://github.com/andogq/qubit","last_synced_at":"2025-04-24T10:33:03.218Z","repository":{"id":222636924,"uuid":"749778677","full_name":"andogq/qubit","owner":"andogq","description":"Seamless RPC for Rust \u0026 TypeScript","archived":false,"fork":false,"pushed_at":"2024-06-06T13:23:49.000Z","size":493,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-06T15:13:09.646Z","etag":null,"topics":["api","jsonrpc","portfolio","rpc-framework","rust","serde","subscriptions","trpc","trpc-rs","ts","ts-rs"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/andogq.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-01-29T11:32:29.000Z","updated_at":"2024-06-08T06:40:28.997Z","dependencies_parsed_at":"2024-02-19T13:41:04.836Z","dependency_job_id":"c079370a-a8f8-4e63-b935-c2a32a5109be","html_url":"https://github.com/andogq/qubit","commit_stats":null,"previous_names":["andogq/rs_ts_api","andogq/rstrpc","andogq/qubit"],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andogq%2Fqubit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andogq%2Fqubit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andogq%2Fqubit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andogq%2Fqubit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andogq","download_url":"https://codeload.github.com/andogq/qubit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223949333,"owners_count":17230275,"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":["api","jsonrpc","portfolio","rpc-framework","rust","serde","subscriptions","trpc","trpc-rs","ts","ts-rs"],"created_at":"2024-11-10T12:19:03.697Z","updated_at":"2024-11-10T12:19:04.216Z","avatar_url":"https://github.com/andogq.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./logo.png\" alt=\"\" width=\"120\" /\u003e\n  \u003ch1\u003eQubit: Seamless RPC For Rust \u0026 TypeScript\u003c/h1\u003e\n\n  \u003ca href=\"https://crates.io/crates/qubit\"\u003e\u003cimg src=\"https://img.shields.io/crates/v/qubit\" alt=\"crates.io\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://docs.rs/qubit/latest/qubit\"\u003e\u003cimg src=\"https://img.shields.io/docsrs/qubit\" alt=\"docs.rs\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@qubit-rs/client\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/%40qubit-rs%2Fclient\" alt=\"npm\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/andogq/qubit/actions/workflows/checks.yml\"\u003e\u003cimg src=\"https://github.com/andogq/qubit/actions/workflows/checks.yml/badge.svg\" alt=\"checks\" /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\nTired of wrestling with RPC boilerplate? Qubit simplifies communication between your Rust services\nand TypeScript clients, offering a type-safe and feature-rich development experience, so you can\nfocus on building amazing applications.\n\n## Features:\n\n- **Generated Type-Safe Clients**: Say goodbye to manual type definitions, Qubit automatically\n  generates TypeScript clients based on your Rust API, ensuring a smooth development experience.\n\n- **Subscriptions**: Build real-time, data-driven applications with subscriptions, allowing for\n  your Rust server to push data directly to connected TypeScript clients.\n\n- **Build Modular APIs**: Organise your API handlers into nested routers, ensuring simplicity and\n  maintainability as your service grows.\n\n- **Serde Compatibility**: Leverage Serde for seamless data serialisation and deserialisation\n  between Rust and TypeScript.\n\n- **Built on JSONRPC 2.0**: Need a non-TypeScript client? Use any JSONRPC client in any language\n  over WebSockets or HTTP.\n\n- **Proven Base**: Built on established libraries like\n  [`ts-rs`](https://github.com/Aleph-Alpha/ts-rs) for type generation and\n  [`jsonrpsee`](https://github.com/paritytech/jsonrpsee) as the JSONRPC implementation.\n\n## Getting Started\n\n1. Add the required dependencies\n\n```toml\n# Cargo.toml\n[dependencies]\nqubit = \"0.6.1\"\n\nts-rs = \"8.1.0\" # Required to generate TS types\nserde = { version = \"1.0\", features = [\"derive\"] } # Required for serialisable types\nfutures = \"0.3.30\" # Required for streaming functionality\n\ntokio = { version = \"1.38\", features = [\"full\"] }\naxum = \"0.7\"\nhyper = { version = \"1.0\", features = [\"server\"] }\n```\n\n```bash\npnpm i @qubit-rs/client@latest\n```\n\n2. Setup a Qubit router, and save the generated types\n\n```rs\n#[handler(query)]\nasync fn hello_world() -\u003e String {\n    \"Hello, world!\".to_string()\n}\n\nlet router = Router::new()\n    .handler(hello_world);\n\nrouter.write_bindings_to_dir(\"./bindings\");\n```\n\n3. Attach the Qubit router to an Axum router, and start it\n\n```rs\n// Create a service and handle\nlet (qubit_service, qubit_handle) = router.to_service(());\n\n// Nest into an Axum router\nlet axum_router = axum::Router::\u003c()\u003e::new()\n    .nest_service(\"/rpc\", qubit_service);\n\n// Start a Hyper server\naxum::serve(\n    tokio::net::TcpListener::bind(\u0026SocketAddr::from(([127, 0, 0, 1], 9944)))\n        .await\n        .unwrap(),\n    axum_router,\n)\n.await\n.unwrap();\n\nqubit_handle.stop().unwrap();\n```\n\n4. Make requests from the TypeScript client\n\n```ts\n// Import transport from client, and generated server type\nimport { build_client, http } from \"@qubit-rs/client\";\nimport type { QubitServer } from \"./bindings\";\n\n// Connect with the API\nconst api = build_client\u003cQubitServer\u003e(http(\"http://localhost:9944/rpc\"));\n\n// Call the handlers\nconst message = await api.hello_world.query();\nconsole.log(\"received from server:\", message);\n```\n\n## Examples\n\nCheckout all the examples in the [`examples`](./examples) directory.\n\n## FAQs\n\n### Qubit?\n\nThe term \"Qubit\" refers to the fundamental unit of quantum information. Just as a qubit can exist\nin a superposition of states, Qubit bridges the gap between Rust and TypeScript, empowering\ndevelopers to create truly exceptional applications.\n\n## Prior Art\n\n- [`rspc`](https://github.com/oscartbeaumont/rspc): Similar concept, however uses a bespoke\nsolution for generating TypeScript types from Rust structs, which isn't completely compatible with\nall of Serde's features for serialising and deserialising structs.\n\n- [`trpc`](https://github.com/trpc/trpc): Needs no introduction, however it being restricted to\nTypeScript backends makes it relatively useless for Rust developers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandogq%2Fqubit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandogq%2Fqubit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandogq%2Fqubit/lists"}