快速开始
应用启动时先创建全局 FastAxios 容器,再通过 axiosUtil.request() 发起请求:
ts
import { axiosUtil, createFastAxios } from "@fast-china/axios";
const fastAxios = createFastAxios({
baseUrl: "https://api.example.com",
timeout: 30_000,
headers: {
Authorization: "Bearer <token>",
},
requestCipher: false,
});
interface User {
id: number;
name: string;
}
const user = await axiosUtil.request<User>({
url: "/users/1",
method: "get",
requestType: "query",
});axiosUtil.request() 默认按 Fast.NET RESTful 响应读取 code、success、message 和 data,成功时直接返回 data。如需原始结构,可通过单次请求选项关闭 simpleDataFormat 或 restfulResult。
