npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

axios-factory-sdk

v1.0.1

Published

基于 axios 的 HTTP 客户端工厂 - 支持 JSON 配置驱动、自动认证、API 测试

Downloads

16

Readme

axios-factory-sdk

npm version License: MIT

基于 axios 的 HTTP 客户端工厂 - 支持 JSON 配置驱动的 API 调用和测试

特性

  • 双模式支持: 兼容旧版 API + 新版 JSON 配置驱动
  • 认证管理: 自动登录、Cookie/Token 管理、401 自动重登
  • 变量流转: 支持 ${var} 模板语法,接口间数据自动传递
  • 测试能力: 可选的测试模块,支持流程编排和断言

安装

npm install axios-factory-sdk

快速开始

方式一: 旧版兼容模式

import { AxiosFactory } from 'axios-factory-sdk';
const client = new AxiosFactory({
  app: {
    name: '测试应用',
    auth: {
      uri: '/api/auth/login',
      data: { username: 'admin', password: '123456' },
      tokenKeys: ['Authorization']
    }
  },
  axios: {
    baseURL: 'https://api.example.com'
  }
});
// 初始化登录
await client.initialize();
// 使用 axios 客户端
const response = await client.axiosClient({ url: '/api/user/me' });
console.log(response.data);

方式二: 新版配置驱动模式

import { AxiosFactory } from 'axios-factory-sdk';
const client = new AxiosFactory({
  baseUrl: 'https://api.example.com',
  app: {
    name: '测试应用',
    auth: {
      enabled: true,
      uri: '/api/auth/login',
      data: { username: 'admin', password: '123456' },
      tokenPath: '$.access_token'
    }
  },
  apis: {
    login: {
      method: 'POST',
      path: '/api/auth/login',
      request: {
        body: { username: 'admin', password: '123456' }
      },
      extract: {
        token: '$.access_token'
      }
    },
    getUserInfo: {
      method: 'GET',
      path: '/api/user/me',
      request: {
        headers: {
          'Authorization': 'Bearer ${token}'
        }
      }
    }
  }
});
// 初始化登录
await client.initialize();
// 执行 API
const result = await client.execute('getUserInfo');
console.log(result.data);

配置说明

ClientConfig

| 字段 | 类型 | 说明 | |-----|------|------| | baseUrl | string | API 埯础地址 | | app | AppConfig | 应用配置 | | axios | AxiosRequestConfig | Axios 配置 | | apis | ApisConfig | API 定义集合 |

AppConfig

| 字段 | 类型 | 说明 | |-----|------|------| | name | string | 应用名称 | | auth | AuthConfig | 认证配置 | | headers | Record<string, string> | 默认请求头 |

AuthConfig

| 字段 | 类型 | 说明 | |-----|------|------| | enabled | boolean | 是否启用认证 | | uri | string | 登录接口 URI | | data | object | 登录请求数据 | | tokenKeys | string[] | 从响应头提取的 Token 键名 | | tokenPath | string | 从响应体提取 Token 的 JSONPath |

ApiConfig

| 字段 | 类型 | 说明 | |-----|------|------| | method | HttpMethod | HTTP 方法 | | path | string | API 路径,| request | RequestConfig | 请求配置 | | extract | Record<string, string> | 变量提取配置 |

API

初始化

await client.initialize();

执行登录认证。

执行 API

const result = await client.execute('apiName', {
  params: { id: 1 },
  query: { page: 1 }
});

使用 axiosClient

const response = await client.axiosClient({
  method: 'GET',
  url: '/api/users/1'
});

License

MIT