Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

orpc

БесплатноБез исполняемых скриптовНе проверен

oRPC is a TypeScript framework for building end-to-end type-safe APIs: you write server procedures with Zod schemas and get a typed client, an RPC endpoint, a…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

oRPC — Type-safe APIs with typed client and OpenAPI

Overview

oRPC lets you declare procedures (input schema, output schema, handler) and group them into a router. From that one router you get a client whose types are inferred from the server (like tRPC), a REST-style handler with real HTTP verbs and paths, and an OpenAPI 3.1 document. A contract-first mode (@orpc/contract) lets you publish the API shape separately from its implementation.

Verified with @orpc/server, @orpc/client, @orpc/contract, @orpc/openapi, @orpc/openapi-client and @orpc/zod 1.16.1 with Zod 4.6; the examples below type-check with tsc --noEmit and ran against a local Node server.

Instructions

Install

npm install @orpc/server @orpc/client zod
npm install @orpc/openapi @orpc/zod        # REST handler + OpenAPI generation
npm install @orpc/contract @orpc/openapi-client   # only for contract-first work
npm install --save-dev typescript tsx @types/node

Use ES modules ("type": "module" in package.json) and "moduleResolution": "Bundler" or "NodeNext" in tsconfig.json; the packages expose sub-path exports such as @orpc/server/node and @orpc/client/fetch.

Define procedures and a router

// src/router.ts
import { ORPCError, os } from '@orpc/server'
import * as z from 'zod'

const Book = z.object({ isbn: z.string(), title: z.string(), priceCents: z.number().int() })

export const listBooks = os
  .route({ method: 'GET', path: '/books', summary: 'List books' })
  .input(z.object({ limit: z.coerce.number().int().min(1).max(100).default(20) }))
  .output(z.array(Book))
  .handler(async ({ input }) =>
    [{ isbn: '9780131103627', title: 'The C Programming Language', priceCents: 4999 }].slice(0, input.limit),
  )

export const getBook = os
  .route({ method: 'GET', path: '/books/{isbn}', summary: 'Get one book' })
  .input(z.object({ isbn: z.string() }))
  .output(Book)
  .handler(async ({ input }) => {
    if (input.isbn !== '9780131103627') throw new ORPCError('NOT_FOUND', { message: 'No such book' })
    return { isbn: input.isbn, title: 'The C Programming Language', priceCents: 4999 }
  })

export const router = { books: { list: listBooks, get: getBook } }
export type AppRouter = typeof router

.route() only matters for the REST/OpenAPI handler; the RPC handler ignores it. Use z.coerce.number() for numeric inputs that arrive in the query string, because query values are strings and the REST handler returned a 400 "Input validation failed" for a plain z.number() when tested.

Serve it over Node's http module

// src/server.ts
import { createServer } from 'node:http'
import { RPCHandler } from '@orpc/server/node'
import { OpenAPIHandler } from '@orpc/openapi/node'
import { router } from './router'

const rpc = new RPCHandler(router)
const rest = new OpenAPIHandler(router)

const server = createServer(async (req, res) => {
  if ((await rpc.handle(req, res, { prefix: '/rpc' })).matched) return
  if ((await rest.handle(req, res, { prefix: '/api' })).matched) return
  res.statusCode = 404
  res.end('Not found')
})

server.listen(4000, '127.0.0.1')

Handlers also exist for fetch-style runtimes (@orpc/server/fetch, @orpc/openapi/fetch) and for Fastify (@orpc/openapi/fastify). Pass per-request context (for example the authenticated user) as { prefix, context } in the second argument of handle.

Call it with a typed client

// src/client.ts
import { createORPCClient } from '@orpc/client'
import { RPCLink } from '@orpc/client/fetch'
import type { RouterClient } from '@orpc/server'
import type { AppRouter } from './router'

const link = new RPCLink({ url: 'http://127.0.0.1:4000/rpc' })
const client: RouterClient<AppRouter> = createORPCClient(link)

const books = await client.books.list({ limit: 5 })
console.log(books[0].title)

Import the router type with import type so no server code ends up in the client bundle. Renaming a field in Book now produces a compile error here.

Generate the OpenAPI document

// src/spec.ts
import { OpenAPIGenerator } from '@orpc/openapi'
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
import { router } from './router'

const generator = new OpenAPIGenerator({ schemaConverters: [new ZodToJsonSchemaConverter()] })
const spec = await generator.generate(router, {
  info: { title: 'Bookshop API', version: '1.0.0' },
  servers: [{ url: '/api' }],
})
console.log(JSON.stringify(spec, null, 2))

Run with npx tsx src/spec.ts > openapi.json. The output is OpenAPI 3.1 with operationId values such as books.list. Feed it to a viewer like Scalar. @orpc/zod/zod4 is the converter for Zod 4.

Contract-first (optional)

Define the shape once, implement it elsewhere, and let non-TypeScript or separate packages consume it.

// src/contract.ts
import { oc } from '@orpc/contract'
import * as z from 'zod'

export const contract = {
  books: {
    find: oc
      .rou
Полный SKILL.md на GitHub

Установить orpc в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл orpc?

oRPC is a TypeScript framework for building end-to-end type-safe APIs: you write server procedures with Zod schemas and get a typed client, an RPC endpoint, a REST endpoint and an OpenAPI document with no code generation. Use when asked to "build a type-safe API", "tRPC alternative with OpenAPI", "contract-first TypeScript API", "generate an OpenAPI spec from my router", or "share types between server and client".

Как установить скилл orpc?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл orpc запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить orpc с