{"name":"oRPC: Typesafe APIs Made Simple with RPC and OpenAPI","description":"oRPC combines RPC and OpenAPI to simplify building end-to-end type-safe APIs. It offers robust features like first-class OpenAPI support, contract-first development, and seamless integration with popular frameworks. This powerful tool ensures type safety from client to server while adhering to industry standards.","github":"https://github.com/unnoq/orpc","url":"https://osrepos.com/repo/unnoq-orpc","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/unnoq-orpc","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/unnoq-orpc.md","json":"https://osrepos.com/repo/unnoq-orpc.json","topics":["TypeScript","API","RPC","OpenAPI","Type Safety","Backend","Frontend","Development"],"keywords":["TypeScript","API","RPC","OpenAPI","Type Safety","Backend","Frontend","Development"],"stars":null,"summary":"oRPC combines RPC and OpenAPI to simplify building end-to-end type-safe APIs. It offers robust features like first-class OpenAPI support, contract-first development, and seamless integration with popular frameworks. This powerful tool ensures type safety from client to server while adhering to industry standards.","content":"## Introduction\n\noRPC is a powerful combination of RPC and OpenAPI, designed to make building APIs that are end-to-end type-safe and adhere to OpenAPI standards simple and efficient. It ensures type-safe inputs, outputs, and errors across your entire application stack, from client to server. With oRPC, developers can leverage contract-first development and integrate seamlessly with various frameworks and runtimes, enhancing both developer experience and application reliability.\n\n## Installation\n\nTo get started with oRPC, you can install the necessary packages using npm or your preferred package manager. The core packages include `@orpc/server` for backend implementation, `@orpc/client` for client-side consumption, and `@orpc/contract` for defining your API structure.\n\nbash\nnpm install @orpc/server @orpc/client @orpc/contract\n\n\n## Examples\n\nHere's a quick overview of how to use oRPC, from defining your API router to consuming it and generating OpenAPI specifications.\n\n### 1. Define your router\n\nStart by defining your API procedures and their schemas using a schema validator like Zod.\n\nts\nimport type { IncomingHttpHeaders } from 'node:http'\nimport { ORPCError, os } from '@orpc/server'\nimport * as z from 'zod'\n\nconst PlanetSchema = z.object({\n  id: z.number().int().min(1),\n  name: z.string(),\n  description: z.string().optional(),\n})\n\nexport const listPlanet = os\n  .input(\n    z.object({\n      limit: z.number().int().min(1).max(100).optional(),\n      cursor: z.number().int().min(0).default(0),\n    }),\n  )\n  .handler(async ({ input }) => {\n    // your list code here\n    return [{ id: 1, name: 'name' }]\n  })\n\nexport const findPlanet = os\n  .input(PlanetSchema.pick({ id: true }))\n  .handler(async ({ input }) => {\n    // your find code here\n    return { id: 1, name: 'name' }\n  })\n\nexport const createPlanet = os\n  .$context<{ headers: IncomingHttpHeaders }>()\n  .use(({ context, next }) => {\n    const user = parseJWT(context.headers.authorization?.split(' ')[1])\n\n    if (user) {\n      return next({ context: { user } })\n    }\n\n    throw new ORPCError('UNAUTHORIZED')\n  })\n  .input(PlanetSchema.omit({ id: true }))\n  .handler(async ({ input, context }) => {\n    // your create code here\n    return { id: 1, name: 'name' }\n  })\n\nexport const router = {\n  planet: {\n    list: listPlanet,\n    find: findPlanet,\n    create: createPlanet\n  }\n}\n\n\n### 2. Create your server\n\nImplement your oRPC server using a runtime-specific handler, for example, Node.js.\n\nts\nimport { createServer } from 'node:http'\nimport { RPCHandler } from '@orpc/server/node'\nimport { CORSPlugin } from '@orpc/server/plugins'\n\nconst handler = new RPCHandler(router, {\n  plugins: [new CORSPlugin()]\n})\n\nconst server = createServer(async (req, res) => {\n  const result = await handler.handle(req, res, {\n    context: { headers: req.headers }\n  })\n\n  if (!result.matched) {\n    res.statusCode = 404\n    res.end('No procedure matched')\n  }\n})\n\nserver.listen(\n  3000,\n  '127.0.0.1',\n  () => console.log('Listening on 127.0.0.1:3000')\n)\n\n\n### 3. Create your client\n\nSet up your client to interact with the oRPC server, ensuring type safety on the client side.\n\nts\nimport type { RouterClient } from '@orpc/server'\nimport { createORPCClient } from '@orpc/client'\nimport { RPCLink } from '@orpc/client/fetch'\n\nconst link = new RPCLink({\n  url: 'http://127.0.0.1:3000',\n  headers: { Authorization: 'Bearer token' },\n})\n\nexport const orpc: RouterClient<typeof router> = createORPCClient(link)\n\n\n### 4. Consume your API\n\nWith the client configured, you can now consume your API with full type safety.\n\nts\nimport { orpc } from './client'\n\nconst planets = await orpc.planet.list({ limit: 10 })\n\n\n### 5. Generate OpenAPI Spec\n\noRPC allows you to generate OpenAPI specifications directly from your router definition.\n\nts\nimport { OpenAPIGenerator } from '@orpc/openapi'\nimport { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'\n\nconst generator = new OpenAPIGenerator({\n  schemaConverters: [new ZodToJsonSchemaConverter()]\n})\n\nconst spec = await generator.generate(router, {\n  info: {\n    title: 'Planet API',\n    version: '1.0.0'\n  }\n})\n\nconsole.log(spec)\n\n\n## Why Use oRPC?\n\noRPC offers several compelling advantages for modern API development:\n\n*   **End-to-End Type Safety**: Guarantees type-safe data flow from client to server, reducing runtime errors and improving code reliability.\n*   **First-Class OpenAPI**: Provides native support for OpenAPI standards, simplifying API documentation, discovery, and integration with other tools.\n*   **Contract-First Development**: Supports defining API contracts before implementation, fostering better collaboration, consistency, and clearer expectations.\n*   **Framework Integrations**: Offers seamless integration with popular frontend frameworks and data fetching libraries such as TanStack Query, SWR, and Pinia Colada.\n*   **Multi-Runtime Support**: Designed to be fast and lightweight across various JavaScript runtimes, including Cloudflare Workers, Deno, Bun, and Node.js.\n*   **Extendability**: Easily extend functionality with a robust plugin system, middleware, and interceptors to tailor oRPC to your specific needs.\n\n## Links\n\n*   GitHub Repository: [https://github.com/unnoq/orpc](https://github.com/unnoq/orpc)\n*   Official Documentation: [https://orpc.dev](https://orpc.dev)","metrics":{"detailViews":2,"githubClicks":1},"dates":{"published":null,"modified":"2026-02-19T12:01:17.000Z"}}