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.
Support fetch headers in link header option
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
- client:
- contract:
- openapi: