The screenshot API for developers -
Try ScreenshotOne
Skip to content

Request Compression Plugin

Compresses request bodies before sending to the server, reducing bandwidth usage and improving performance for large payloads.

Client

Use RequestCompressionLinkPlugin to compress request bodies. Configure the compression scheme and size threshold:

ts
import { RequestCompressionLinkPlugin } from '@orpc/client/plugins'

const link = new RPCLink({
  plugins: [
    new RequestCompressionLinkPlugin({
      /**
       * The compression scheme to use for request compression.
       * Supported values: 'gzip' | 'deflate' | 'deflate-raw'
       *
       * @default 'gzip'
       */
      encoding: 'gzip',

      /**
       * The minimum request size in bytes required to trigger compression.
       * Requests smaller than this threshold will not be compressed to avoid overhead.
       * If the request size cannot be determined, compression will still be applied.
       *
       * @default 1024 (1KB)
       */
      threshold: 1024
    }),
  ],
})

INFO

The link can be any supported oRPC link, such as RPCLink, OpenAPILink, or a custom one.

Server

Use RequestCompressionHandlerPlugin to decompress request bodies. The plugin automatically detects the client's compression scheme based on the Content-Encoding header:

handler
ts
import { RequestCompressionHandlerPlugin } from '@orpc/server/plugins'

const handler = new RPCHandler(router, {
  plugins: [
    new RequestCompressionHandlerPlugin(),
  ],
})

INFO

The handler can be any supported oRPC handler, such as RPCHandler, OpenAPIHandler, or a custom one.

Released under the MIT License.