Skip to content
oRPC
Esc
navigateopen⌘Jpreview
On this page

v1.8.6

Response Validation Plugin docs

The Response Validation Plugin validates server responses against your contract schema, ensuring that data returned from your server matches the expected types defined in your contract.

import { RPCLink } from '@orpc/client/fetch'
import { ResponseValidationPlugin } from '@orpc/contract/plugins'

const link = new RPCLink({
  url: 'http://localhost:3000/rpc',
  plugins: [
    new ResponseValidationPlugin(contract),
  ],
})

const client: ContractRouterClient<typeof contract> = createORPCClient(link)

[!TIP] Beyond response validation, this plugin also serves special purposes such as Expanding Type Support for OpenAPI Link.

 import { RPCLink } from '@orpc/client/fetch'
 const link = new RPCLink({
   url: `${typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000'}/rpc`,
   headers: async () => {
     if (typeof window !== 'undefined') {
       return {}
     }

    const { headers } = await import('next/headers')
-    return Object.fromEntries(await headers())
+    return await headers()
   },
 })

   🚀 Features

    View changes on GitHub

Last updated on September 1, 2025

Was this page helpful?