@epilot/axios-large-response

中文文档
0.0.3发布于 2026/09/10MITTypeScriptESM + CJS零依赖近 30 天下载 1.8万

Axios plugin to intercept large responses

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Clients that don't dispatch through axios ( withLargeRespon…
  4. Options
  5. How it works

Axios Large Response

@epilot/axios-large-response downloads

An Axios interceptor designed to handle large responses. By default, it assumes that your backend uses @epilot/large-response-middleware, as described in the large-response-middleware README. However, it also supports custom callback function to fetch large payloads from a reference data, customizable reference property names, headers, and other options. See below for details.

It supports per-request options, so you can enable/disable the interceptor for a specific request (the axios config namespace is axios-large-response - please check the Usage section for more details). For now, it is disabled by default, however we can do some combinations based on the use cases, for example, we can disable it globally and enable it per-request if needed.

The interceptor is disabled by default, so you need to explicitly enable it.

Installation

pnpm add @epilot/axios-large-response
npm install @epilot/axios-large-response
yarn add @epilot/axios-large-response

Usage

import { axiosLargeResponse } from '@epilot/axios-large-response';
import axios from 'axios';

// Axios instance
const axiosInstance = axios.create();

// Example 1: disable interceptor globally so we enable it per-request
axiosLargeResponse(axiosInstance, {
  // enabled: false, -> disabled by default
  // ... other global options
});
...
const response = await axiosInstance.get('https://api.example.com/data', {
  'axios-large-response': {
    enabled: true,
    headerFlag: 'application/custom-large-response.vnd+json',
    refProperty: '$customRef',
    debug: true,
    onFetchLargePayloadFromRef: async (refUrl) => {
      // Custom handling for this specific request
      const response = await axios.get(refUrl);
      return response.data;
    }
  }
});

// Example 2: enable interceptor globally so we disable it per-request
axiosLargeResponse(axiosInstance, {
  enabled: true,
  // ... other global options
});
...
const response =  await axiosInstance.get('https://api.example.com/data', {
  'axios-large-response': {
    enabled: false
  }
});

Clients that don't dispatch through axios (withLargeResponse)

Interceptors only run for requests that go through the axios adapter. A client configured with its own runner bypasses that adapter entirely, so the interceptor never sees those requests - and responses over the transport's payload limit fail with a 413. The most common case is service-to-service calls over an AWS Lambda invoke, wired up with openapi-client-axios' registerRunner.

withLargeResponse wraps such a runner and gives it the same behaviour as the interceptor:

import { withLargeResponse } from '@epilot/axios-large-response';
import { getLambdaRunner } from 'openapi-lambda-adapter';

client.api.registerRunner(
  withLargeResponse(getLambdaRunner(lambdaName, context), {
    enabled: true,
    // ... same options as the interceptor
  }),
);

The runner is described structurally - anything with a runRequest(request, ...rest) method whose first argument is an object qualifies - so this is not tied to AWS Lambda, or to any particular transport. HTTP clients, in-process calls and test doubles all work, and trailing arguments (such as openapi-client-axios' operation and context) are passed through untouched. The package gains no dependency beyond axios as a result.

Per-request options work as they do on the interceptor: set them under the axios-large-response key on the request and they override the global ones for that call. The key is stripped before the request reaches your runner.

client.getThings({}, null, {
  'axios-large-response': { onFetchLargePayloadFromRef: myAuthenticatedFetch },
});

enabled works per request too, so the combination from Example 1 above - disabled globally, enabled only for the calls that need it - works on a runner as well:

client.api.registerRunner(withLargeResponse(getLambdaRunner(lambdaName, context)));
...
client.getThings({}, null, {
  'axios-large-response': { enabled: true },
});

One note:

  • The wrapped runner keeps the original's prototype and own properties. This matters: openapi-client-axios invokes a registered runner as runner.runRequest(request, operation, runner.context), and the lambda runner reads the target function name off that context. Class instances keep their methods and their identity, and runRequest stays bound to the original, so a method that reads this still works. Wrap your runner rather than rebuilding it.

Options

NameTypeDefaultDescription
enabledBooleanfalseEnable/disable the interceptor
headerFlagString'application/large-response.vnd+json'Content type header indicating a large payload reference response
refPropertyString'$payload_ref'Property name containing the reference URL in the response
debugBooleanfalseEnable debug logging
loggerObjectconsoleLogger object with debug(), error() and warn() methods
onFetchLargePayloadFromRefFunctionFetches the reference URL and returns the full payloadCallback function to fetch the full payload from the reference URL
errorPayloadUnknown/AnyundefinedError payload to return if the reference URL is not found or something goes wrong - this will be returned in the response data instead of throwing an error. Any value other than undefined counts as configured, falsy ones (null, 0, '', false) included
disableWarningsBooleanfalseDisable warnings, only available globally in the options

For debug purposes, you can also set the AXIOS_INTERCEPTOR_LARGE_RESPONSE_DEBUG environment variable to true or 1 to enable debug logging.

How it works

  1. Adds the appropriate Accept header to requests to indicate large payload support;
  2. Detects responses with the configured header content type;
  3. If the response contains a reference in the specified refProperty, automatically fetches the full payload;
  4. Returns the complete data in the response.

Example server response for a large payload:

{
  "$payload_ref": "https://api.example.com/large-payloads/123"
}

After interceptor processing, the response becomes:

{
  "huge": "data",
  "nested": {
    "complex": "structure"
  }
}

版本与发布记录

@epilot/axios-large-response 共发布 5 个版本,首次发布于 2025/02/18;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.0.3latest2026/09/102 个月前
0.0.3-alpha.22026/08/063 个月前
0.0.3-alpha.12026/08/053 个月前
0.0.22025/03/071.7 年前
0.0.12025/02/181.7 年前

关于 @epilot/axios-large-response 的常见问题

@epilot/axios-large-response 是什么?

Axios plugin to intercept large responses

如何安装 @epilot/axios-large-response?

在项目目录运行 npm install @epilot/axios-large-response,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:axios(>=0.25.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@epilot/axios-large-response 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@epilot/axios-large-response 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@epilot/axios-large-response 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@epilot/axios-large-response 可以商用吗?

@epilot/axios-large-response 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@epilot/axios-large-response 的下载量有多少?

根据 npm 官方下载统计,@epilot/axios-large-response 在 2026/10/14 – 2026/11/12 这 30 天内被下载 17,835 次,日均约 595 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@epilot/axios-large-response 还在维护吗?

最新版本 0.0.3 发布于 2026/09/10(2 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/02/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。