Tang Emperors API
Overview
This skill provides integration with a local backend API that returns information about the first three emperors of the Tang Dynasty (唐朝前3代皇帝). The API is deployed locally at http://127.0.0.1:8080 with the endpoint GET /api/v1/test.
Quick Start
Fetch Tang Dynasty emperor information:
CODEBLOCK0
Output formatted as human-readable text:
CODEBLOCK1
Output raw JSON:
CODEBLOCK2
API Details
- - Base URL: INLINECODE2
- Endpoint: INLINECODE3
- Method: GET
- Returns: JSON data about the first three Tang Dynasty emperors
Error Handling
The script includes comprehensive error handling:
- - Connection errors: Backend not running or unreachable
- Timeout errors: API response timeout (10s default)
- HTTP errors: Invalid HTTP responses (404, 500, etc.)
- JSON parsing errors: Malformed response data
- Unexpected errors: Other runtime errors
Usage Patterns
Direct API call:
CODEBLOCK3
Via Python script (recommended):
CODEBLOCK4
Programmatic access in Python:
CODEBLOCK5
Resources
scripts/gettangemperors.py
Python client for the Tang Emperors API with:
- -
get_tang_emperors(): Fetches raw JSON data from API - INLINECODE5 : Formats data for human-readable output
- CLI support with
--json flag for raw JSON output - Comprehensive error handling and timeout management
The script can be:
- - Executed directly from command line
- Imported as a module in other Python code
- Used by Codex for automated API interactions
Notes
- - Ensure the local backend is running before making API calls
- The API expects a GET request with no parameters
- Response format may vary; the script handles common patterns (list, dict with 'emperors' key, dict with 'data' key)
- Default timeout is 10 seconds; adjust in script if needed for your environment
唐皇API
概述
该技能提供与本地后端API的集成,该API返回唐朝前三位皇帝的信息。API部署在本地地址http://127.0.0.1:8080,端点为GET /api/v1/test。
快速开始
获取唐朝皇帝信息:
bash
python3 scripts/gettangemperors.py
输出为人类可读文本格式:
bash
python3 scripts/gettangemperors.py
输出原始JSON格式:
bash
python3 scripts/gettangemperors.py --json
API详情
- - 基础URL:http://127.0.0.1:8080
- 端点:/api/v1/test
- 方法:GET
- 返回:关于唐朝前三位皇帝的JSON数据
错误处理
脚本包含全面的错误处理:
- - 连接错误:后端未运行或无法访问
- 超时错误:API响应超时(默认10秒)
- HTTP错误:无效的HTTP响应(404、500等)
- JSON解析错误:响应数据格式错误
- 意外错误:其他运行时错误
使用模式
直接API调用:
bash
curl http://127.0.0.1:8080/api/v1/test
通过Python脚本(推荐):
bash
python3 scripts/gettangemperors.py
在Python中以编程方式访问:
python
from scripts.gettangemperors import gettangemperors, formatemperordata
data = gettangemperors()
formatted = formatemperordata(data)
print(formatted)
资源
scripts/gettangemperors.py
用于唐皇API的Python客户端,包含:
- - gettangemperors():从API获取原始JSON数据
- formatemperordata():格式化数据以输出人类可读内容
- 支持--json标志的CLI接口,用于输出原始JSON
- 全面的错误处理和超时管理
该脚本可以:
- - 直接从命令行执行
- 作为模块导入到其他Python代码中
- 由Codex用于自动化的API交互
注意事项
- - 在进行API调用前,请确保本地后端正在运行
- API期望GET请求且不带参数
- 响应格式可能有所不同;脚本处理常见模式(列表、包含emperors键的字典、包含data键的字典)
- 默认超时时间为10秒;可根据环境在脚本中调整