Project handlers
.use(fn) replaces a handler; handlers do not accumulate like Axios interceptor queues.
Message
fastAxios.message.success.use((message) => {});
fastAxios.message.warning.use((message) => {});
fastAxios.message.info.use((message) => {});
fastAxios.message.error.use((message) => {});Defaults to console output when unregistered. The request core does not duplicate logging before throwing.
Loading
fastAxios.loading.show.use((text) => {});
fastAxios.loading.close.use((options) => {});The default implementation does nothing. The SDK does not maintain a global concurrent-request counter; application handlers must prevent one request from closing another request's loading indicator.
Cache
fastAxios.cache.get.use((key) => storage.get(key));
fastAxios.cache.set.use((key, value) => storage.set(key, value));Defaults to an in-process Map. Readers should return null or undefined for cache misses; false, 0, and empty strings are valid cached values.
Caching applies only to requests satisfying all of these conditions:
cache: true且显式非空cacheNamespace/ 容器 namespace;- GET;
restfulResult: true;simpleDataFormat: true。
Caches the final value returned to the caller, not the raw AxiosResponse.
Crypto
fastAxios.crypto.encrypt.use((config, timestamp) => {
// May modify data, params, or headers.
});
fastAxios.crypto.decrypt.use((response, options) => {
return response.data;
});The default encryptor leaves requests unchanged; the default decryptor returns response.data. requestCipher: true alone provides no encryption security. Register implementations matching the server protocol.
Interceptors
fastAxios.interceptors.request.use((config) => {});
fastAxios.interceptors.response.use((response, options) => {
return undefined;
});
fastAxios.interceptors.responseError.use((error, options) => {
return undefined;
});requestmay mutate the Axios internal request configuration.- A non-nullish
responseresult takes over success handling, skipping file, RESTful, decryption, and caching logic. - A non-nullish
responseErrorresult replaces the final rejection; non-Error values are wrapped in AxiosError.
These are single Fast project handlers. Axios instances still use standard request/response interceptors for their lifecycle.
MessageBox
fastAxios.messageBox.confirm.use(async (options) => {
// Resolve on confirmation; throw or return a rejected Promise on cancellation.
});Defaults to uni.showModal, then browser window.confirm. Resolves on confirmation; rejects on cancellation, platform failure, or unsupported runtimes.
fastAxios.message.success Success
Calls the current success-message handler.
Signature
(message: string): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.message.success("操作完成");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
message | string | Required | Message text to display. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.message.success.use Provide
Replaces the success-message handler.
Signature
use(fn: (message: string) => void): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.message.success.use((message) => console.log("success", message));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | (message: string) => void | Required | New message-display function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value; subsequent requests use the new implementation. |
fastAxios.message.warning Warning
Calls the current warning-message handler.
Signature
(message: string): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.message.warning("操作完成");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
message | string | Required | Message text to display. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.message.warning.use Provide
Replaces the warning-message handler.
Signature
use(fn: (message: string) => void): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.message.warning.use((message) => console.log("warning", message));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | (message: string) => void | Required | New message-display function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value; subsequent requests use the new implementation. |
fastAxios.message.info Info
Calls the current info-message handler.
Signature
(message: string): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.message.info("操作完成");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
message | string | Required | Message text to display. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.message.info.use Provide
Replaces the info-message handler.
Signature
use(fn: (message: string) => void): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.message.info.use((message) => console.log("info", message));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | (message: string) => void | Required | New message-display function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value; subsequent requests use the new implementation. |
fastAxios.message.error Error
Calls the current error-message handler.
Signature
(message: string): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.message.error("操作完成");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
message | string | Required | Message text to display. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.message.error.use Provide
Replaces the error-message handler.
Signature
use(fn: (message: string) => void): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.message.error.use((message) => console.log("error", message));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | (message: string) => void | Required | New message-display function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value; subsequent requests use the new implementation. |
fastAxios.loading.show Loading
Calls the current loading-show handler.
Signature
(text: string): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.loading.show("加载中...");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
text | string | Required | Loading message. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.loading.show.use Provide
Replaces the loading-show handler.
Signature
use(fn: (text: string) => void): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.loading.show.use((text) => console.log("show loading", text));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | (text: string) => void | Required | Application UI show function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.loading.close Close
Calls the current loading-close handler.
Signature
(options: AxiosOptions): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.loading.close({ loading: true });Input
| Input | Type | Required / default | Description |
|---|---|---|---|
options | AxiosOptions | Required | Current Fast request options, usable for concurrency counting. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.loading.close.use Provide
Replaces the loading-close handler.
Signature
use(fn: (options: AxiosOptions) => void): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.loading.close.use((options) => console.log("close loading", options));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | (options: AxiosOptions) => void | Required | Application UI close function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.cache.get Read
Calls the cache reader with the request's unique key.
Signature
(key: string): unknown;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
const result = fastAxios.cache.get("GET&/users");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
key | string | Required | Cache key generated by the request flow. |
Returns
| Value | Type | Description |
|---|---|---|
result | unknown | Cached value; misses should be null or undefined. |
fastAxios.cache.get.use Provide
Replaces the cache reader.
Signature
use(fn: (key: string) => unknown): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
const store = new Map<string, unknown>();
fastAxios.cache.get.use((key) => store.get(key));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | (key: string) => unknown | Required | New cache-reading function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.cache.set Write
Calls the current cache writer.
Signature
(key: string, value: unknown): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.cache.set("GET&/users", [{ id: 1 }]);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
key | string | Required | Request cache key. |
value | unknown | Required | Final result returned to the caller. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.cache.set.use Provide
Replaces the cache writer.
Signature
use(fn: (key: string, value: unknown) => void): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
const store = new Map<string, unknown>();
fastAxios.cache.set.use((key, value) => {
store.set(key, value);
});Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | (key: string, value: unknown) => void | Required | New cache-writing function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.crypto.encrypt Encrypt
Calls the encryptor before sending the request.
Signature
<Input>(config: InternalAxiosRequestConfig<Input>, timestamp: number): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
import { AxiosHeaders, type InternalAxiosRequestConfig } from "axios";
const config = { headers: new AxiosHeaders() } as InternalAxiosRequestConfig;
fastAxios.crypto.encrypt(config, Date.now());Input
| Input | Type | Required / default | Description |
|---|---|---|---|
config | InternalAxiosRequestConfig<Input> | Required | Mutable Axios request configuration. |
timestamp | number | Required | Unix millisecond timestamp shared by the current request. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value; the encryptor mutates config. |
fastAxios.crypto.encrypt.use Provide
Replaces the request encryptor.
Signature
use(fn: CryptoEncryptHandle): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.crypto.encrypt.use((config, timestamp) => {
config.headers.set("X-Time", timestamp);
});Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | CryptoEncryptHandle | Required | New request encryption or signing function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.crypto.decrypt Decrypt
Calls the current response decryptor.
Signature
<Output, Input>(response: AxiosResponse<Output, Input>, options: FastAxiosRequestConfig<Input>): unknown;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
import axios from "axios";
const requestOptions = { url: "/users" };
const response = await axios.request(requestOptions);
const result = fastAxios.crypto.decrypt(response, requestOptions);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
response | AxiosResponse<Output, Input> | Required | Response that has passed RESTful status validation. |
options | FastAxiosRequestConfig<Input> | Required | Current Fast request options. |
Returns
| Value | Type | Description |
|---|---|---|
result | unknown | Complete response body for subsequent simplified-data unwrapping. |
fastAxios.crypto.decrypt.use Provide
Replaces the response decryptor.
Signature
use(fn: CryptoDecryptHandle): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.crypto.decrypt.use((response) => response.data);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | CryptoDecryptHandle | Required | New response decryption function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.interceptors.request Request
Calls the project request preprocessing handler.
Signature
<Input>(config: InternalAxiosRequestConfig<Input>): void | Promise<void>;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
import { AxiosHeaders, type InternalAxiosRequestConfig } from "axios";
const config = { headers: new AxiosHeaders() } as InternalAxiosRequestConfig;
fastAxios.interceptors.request(config);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
config | InternalAxiosRequestConfig<Input> | Required | Mutable configuration of the request about to be sent. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | Promise<void> | No return value. |
fastAxios.interceptors.request.use Provide
Replaces the project request preprocessing handler.
Signature
use(fn: InterceptorsRequestHandle): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.interceptors.request.use((config) => {
config.headers.set("Authorization", "Bearer token");
});Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | InterceptorsRequestHandle | Required | New request handler. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.interceptors.response Response
Calls the project success-response handler.
Signature
<Output, Input>(response: AxiosResponse<Output, Input>, options: FastAxiosRequestConfig<Input>): unknown;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
import axios from "axios";
const requestOptions = { url: "/users" };
const response = await axios.request(requestOptions);
const result = fastAxios.interceptors.response(response, requestOptions);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
response | AxiosResponse<Output, Input> | Required | Successful Axios response. |
options | FastAxiosRequestConfig<Input> | Required | Current Fast request options. |
Returns
| Value | Type | Description |
|---|---|---|
result | unknown | A non-nullish value takes over default response processing; nullish values continue it. |
fastAxios.interceptors.response.use Provide
Replaces the project success-response handler.
Signature
use(fn: InterceptorsResponseHandle): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.interceptors.response.use((response) => (response.headers["x-custom"] ? response.data : undefined));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | InterceptorsResponseHandle | Required | New success-response handler. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.interceptors.responseError Error
Calls the project failed-response handler.
Signature
<Input>(error: AxiosError<unknown, Input>, options: FastAxiosRequestConfig<Input>): unknown;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
import { AxiosError } from "axios";
const error = new AxiosError("Network Error");
const requestOptions = { url: "/users" };
const result = fastAxios.interceptors.responseError(error, requestOptions);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
error | AxiosError<unknown, Input> | Required | Axios request failure object. |
options | FastAxiosRequestConfig<Input> | Required | Current Fast request options. |
Returns
| Value | Type | Description |
|---|---|---|
result | unknown | A non-nullish value replaces the final thrown error. |
fastAxios.interceptors.responseError.use Provide
Replaces the project failed-response handler.
Signature
use(fn: InterceptorsResponseErrorHandle): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.interceptors.responseError.use((error) => (error.response?.status === 401 ? new Error("登录失效") : undefined));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | InterceptorsResponseErrorHandle | Required | New failed-response handler. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
fastAxios.messageBox.confirm Confirm
Opens a confirmation dialog and awaits the user's choice.
Signature
(options: MessageBoxOptions): Promise<void>;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
await fastAxios.messageBox.confirm({ message: "确认删除?", type: "warning" });Input
| Input | Type | Required / default | Description |
|---|---|---|---|
options | MessageBoxOptions | Required | Body text, type, and button labels. |
Returns
| Value | Type | Description |
|---|---|---|
result | Promise<void> | Resolves on confirmation; rejects on cancellation or platform failure. |
fastAxios.messageBox.confirm.use Provide
Replaces the confirmation handler.
Signature
use(fn: MessageBoxHandle): void;Example
import { createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({ baseUrl: "/api" }, true);
fastAxios.messageBox.confirm.use(async (options) => {
console.log(options.message);
});Input
| Input | Type | Required / default | Description |
|---|---|---|---|
fn | MessageBoxHandle | Required | New asynchronous confirmation function. |
Returns
| Value | Type | Description |
|---|---|---|
result | void | No return value. |
Cache scope and async handlers
Set cache.namespace to an identity/tenant/locale context; an empty string disables request caching. Call cache.clear() on logout or cookie-session changes. Namespace changes invalidate entries too; generations prevent late requests from repopulating a new session. Identity is hashed before the cache key reaches a storage handler. Request caching is skipped without Web Crypto hashing.
Custom persistent backends own physical deletion and TTL. Container prefixes and generations prevent old persisted keys being revived. A cache hit still executes the request hook and Axios cancellation checks, but not Loading, decryption or response takeover twice.
The request pipeline awaits request, response and responseError results. Nullish async takeover results continue defaults; rejections propagate. Non-Axios errors, cancellation and explicit offline handling retain their specialized paths without responseError. Message, Loading and Crypto hooks remain synchronous. Manual invocation leaves awaiting and pairing to the caller.
