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.
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:
- Support fetch headers in link options - by @dinwwwh in https://github.com/middleapi/orpc/issues/946 (216e5)
- contract:
- Add failed data to ValidationError for debugging - by @dinwwwh in https://github.com/middleapi/orpc/issues/949 (f437d)
- Response Validation Plugin - by @dinwwwh in https://github.com/middleapi/orpc/issues/953 (5a170)
- openapi:
- Form-data helpers - by @dinwwwh in https://github.com/middleapi/orpc/issues/951 (4b3a4)