# api_toolkit **Repository Path**: simplecoder-1/api_toolkit ## Basic Information - **Project Name**: api_toolkit - **Description**: 强大的命令行 API 调试工具,为开发者打造。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-22 - **Last Updated**: 2026-02-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # API Toolkit [![Gitee](https://img.shields.io/badge/Gitee-api__toolkit-red?style=flat-square&logo=gitee)](https://gitee.com/simplecoder-1/api_toolkit) [![Python](https://img.shields.io/badge/Python-3.8+-blue?style=flat-square&logo=python)](https://www.python.org/) [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](LICENSE) 强大的命令行 API 调试工具,为开发者打造。 ## 功能特性 - **多种 HTTP 方法**:GET、POST、PUT、PATCH、DELETE、HEAD、OPTIONS - **认证方式**:Basic 认证、Bearer Token、API Key - **自定义请求头**:灵活配置请求头和 URL 参数 - **变量替换**:支持 `{{变量名}}` 语法 - **环境管理**:多环境切换配置 - **请求历史**:自动保存所有请求记录 - **收藏请求**:保存常用请求方便复用 - **彩色输出**:格式化的 JSON 响应显示 - **交互式 Shell**:友好的人机交互模式 ## 安装 ```bash # 克隆仓库 git clone https://gitee.com/simplecoder-1/api_toolkit.git # 安装依赖 cd api_toolkit pip install -r requirements.txt ``` ## 快速开始 ### 命令行模式 ```bash # 发送 GET 请求 python main.py request GET https://httpbin.org/get # 发送 POST 请求(带 JSON body) python main.py request POST https://httpbin.org/post -d '{"name":"test"}' # 自定义请求头 python main.py request GET https://api.example.com/users -H "Authorization:Bearer token" # URL 参数 python main.py request GET https://api.example.com/users -p "page=1&size=10" # Basic 认证 python main.py request GET https://api.example.com/protected --auth-basic username:password # Bearer Token python main.py request GET https://api.example.com/protected --auth-bearer your_token_here # API Key python main.py request GET https://api.example.com/protected --auth-api-key X-API-Key:your_key ``` ### 交互式 Shell 模式 ```bash python shell.py ``` ``` api> help api> get https://httpbin.org/get api> post https://httpbin.org/post -d '{"name":"test"}' api> header Content-Type:application/json api> var API_URL=https://api.example.com api> history api> exit ``` ## 命令说明 ### 请求相关 | 参数 | 说明 | |------|------| | `-H, --headers` | 请求头(格式:key:value,key2:value2) | | `-d, --body` | 请求体 | | `-p, --params` | URL 参数(格式:key=value,key2=value2) | | `--auth-basic` | Basic 认证(格式:username:password) | | `--auth-bearer` | Bearer Token | | `--auth-api-key` | API Key(格式:key_name:key_value) | | `--var` | 变量(格式:key=value) | ### 环境管理 ```bash # 列出环境 python main.py env list # 创建环境 python main.py env create dev API_URL=https://dev.api.com # 切换环境 python main.py env use 1 # 查看当前环境 python main.py env show ``` ### 历史记录和收藏 ```bash # 查看历史 python main.py history -n 20 # 清空历史 python main.py history-clear # 保存请求 python main.py save --name "获取用户列表" --method GET --url https://api.example.com/users # 列出已保存的请求 python main.py saved # 加载并执行保存的请求 python main.py load 1 ``` ## 项目结构 ``` api_toolkit/ ├── main.py # 命令行入口 ├── shell.py # 交互式 Shell ├── http_client.py # HTTP 客户端核心 ├── formatter.py # 响应格式化输出 ├── storage.py # SQLite 数据持久化 ├── requirements.txt └── api Windows 启动脚本 ``` ## 使用示例 ### 开发环境配置 ```bash # 创建开发环境 python main.py env create dev API_URL=https://dev.example.com API_KEY=dev_key_123 # 创建生产环境 python main.py env create prod API_URL=https://api.example.com API_KEY=prod_key_456 # 切换到开发环境 python main.py env use 1 # 发送请求(自动替换变量) python main.py request GET {{API_URL}}/users --auth-bearer {{API_KEY}} ``` ### 调试 RESTful API ```bash # 获取用户列表 python main.py request GET https://api.example.com/users -p "page=1&size=20" # 创建用户 python main.py request POST https://api.example.com/users \ -H "Content-Type:application/json" \ -d '{"username":"test","email":"test@example.com"}' # 更新用户 python main.py request PUT https://api.example.com/users/123 \ -H "Content-Type:application/json" \ -d '{"status":"active"}' # 删除用户 python main.py request DELETE https://api.example.com/users/123 ``` ## 许可证 MIT License - 查看 [LICENSE](LICENSE) 文件了解详情。 ## 作者 - GitHub: [https://github.com/simplecoder-1](https://github.com/simplecoder-1) - Gitee: [https://gitee.com/simplecoder-1](https://gitee.com/simplecoder-1)