|
| 1 | +# uapi-sdk-browser |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +[](https://www.typescriptlang.org/) |
| 6 | +[](https://uapis.cn/) |
| 7 | + |
| 8 | +> [!NOTE] |
| 9 | +> 所有接口的 Browser (TypeScript) 示例都可以在 [UApi](https://uapis.cn/docs/introduction) 的接口文档页面,向下滚动至 **快速启动** 区块后直接复制。 |
| 10 | +
|
| 11 | +## 快速开始 |
| 12 | + |
| 13 | +```bash |
| 14 | +npm i uapi-sdk-browser |
| 15 | +``` |
| 16 | + |
| 17 | +```ts |
| 18 | +import { UapiClient } from 'uapi-sdk-browser' |
| 19 | + |
| 20 | +const client = new UapiClient('https://uapis.cn/api/v1') |
| 21 | +const result = await client.social.getSocialQqUserinfo({ qq: '10001' }) |
| 22 | +console.log(result) |
| 23 | +``` |
| 24 | + |
| 25 | +## 特性 |
| 26 | + |
| 27 | +现在你不再需要反反复复的查阅文档了。 |
| 28 | + |
| 29 | +只需在 IDE 中键入 `client.`,所有核心模块——如 `social`、`game`、`image`——即刻同步展现。进一步输入即可直接定位到 `getSocialQqUserinfo` 这样的具体方法,其名称与文档的 `operationId` 严格保持一致,确保了开发过程的直观与高效。 |
| 30 | + |
| 31 | +所有方法签名只接受真实且必需的参数。当你在构建请求时,TypeScript 会即时提示 `qq`、`username` 等键名,这彻底杜绝了在对象字面量中因键名拼写错误而导致的运行时错误。 |
| 32 | + |
| 33 | +针对 401、404、429 等标准 HTTP 响应,SDK 已将其统一映射为 `UapiError`。错误对象自带 `code`、`status` 与 `details` 字段,确保你在浏览器日志中能第一时间准确、快速地诊断问题。 |
| 34 | + |
| 35 | +SDK 采用原生 `fetch`,自动补上 `Authorization` 头且不依赖任何 Node.js API;需要自定义超时或重试时,只要包装 `_request` 或替换调用处即可。 |
| 36 | + |
| 37 | +如果你需要查看字段细节或内部逻辑,仓库中的 `./internal` 目录同步保留了由 `openapi-generator` 生成的完整结构体,随时可供参考。 |
| 38 | + |
| 39 | +## 错误模型概览 |
| 40 | + |
| 41 | +| HTTP 状态码 | SDK 错误类型 | 附加信息 | |
| 42 | +|-------------|-------------|----------------------------------------------| |
| 43 | +| 401/403 | `UapiError` | `code`、`status`、`details` | |
| 44 | +| 404 | `UapiError` | `code`、`status` | |
| 45 | +| 400 | `UapiError` | `code`、`status`、`details` | |
| 46 | +| 429 | `UapiError` | `code`、`status`、`retry_after_seconds` | |
| 47 | +| 5xx | `UapiError` | `code`、`status` | |
| 48 | + |
| 49 | +## 其他 SDK |
| 50 | + |
| 51 | +| 语言 | 仓库地址 | |
| 52 | +|-------------|--------------------------------------------------------------| |
| 53 | +| Go | https://github.com/AxT-Team/uapi-go-sdk | |
| 54 | +| Python | https://github.com/AxT-Team/uapi-python-sdk | |
| 55 | +| TypeScript| https://github.com/AxT-Team/uapi-typescript-sdk | |
| 56 | +| Browser (TypeScript/JavaScript)(当前)| https://github.com/AxT-Team/uapi-browser-sdk | |
| 57 | +| Java | https://github.com/AxT-Team/uapi-java-sdk | |
| 58 | +| PHP | https://github.com/AxT-Team/uapi-php-sdk | |
| 59 | +| C# | https://github.com/AxT-Team/uapi-csharp-sdk | |
| 60 | +| C++ | https://github.com/AxT-Team/uapi-cpp-sdk | |
| 61 | +| Rust | https://github.com/AxT-Team/uapi-rust-sdk | |
| 62 | + |
| 63 | +## 文档 |
| 64 | + |
| 65 | +访问 [UApi文档首页](https://uapis.cn/docs/introduction) 并选择任意接口,向下滚动到 **快速启动** 区块即可看到最新的 Browser (TypeScript) 示例代码。 |
0 commit comments