Skip to content
oRPC
Esc
navigateopen⌘Jpreview
On this page

v1.10.2

OpenAPI - custom error format docs

By default, OpenAPIHandler, OpenAPIGenerator, and OpenAPILink share the same error response format. You can customize one, some, or all of them based on your requirements.

const handler = new OpenAPIHandler(router, {
  customErrorResponseBodyEncoder(error) {
    return error.toJSON()
  },
})

Native Fastify adapter docs

Previously, oRPC in Fastify used the Node adapter, which didn’t integrate well with Fastify’s ecosystem (e.g., cookies, helpers, middleware). This native adapter supports Fastify’s request/reply APIs directly, enabling full access to Fastify features within oRPC.

import Fastify from 'fastify'
import { RPCHandler } from '@orpc/server/fastify'
import { onError } from '@orpc/server'

const handler = new RPCHandler(router, {
  interceptors: [
    onError((error) => {
      console.error(error)
    })
  ]
})

const fastify = Fastify()

fastify.addContentTypeParser('*', (request, payload, done) => {
  // Fully utilize oRPC feature by allowing any content type
  // And let oRPC parse the body manually by passing `undefined`
  done(null, undefined)
})

fastify.all('/rpc/*', async (req, reply) => {
  const { matched } = await handler.handle(req, reply, {
    prefix: '/rpc',
    context: {} // Provide initial context if needed
  })

  if (!matched) {
    reply.status(404).send('Not found')
  }
})

fastify.listen({ port: 3000 }).then(() => console.log('Server running on http://localhost:3000'))

   🚀 Features

[!TIP] If you find oRPC valuable and would like to support its development, you can do so here.

    View changes on GitHub

Last updated on October 26, 2025

Was this page helpful?