开发者文档
将 Free API Hub 集成到你的应用所需的一切:快速开始、代码示例、认证说明与错误处理。
快速开始
三步即可开始使用 Free API Hub。
1
注册账号
填写邮箱和密码,快速完成注册。
2
获取 API Key
在开发者后台创建你的 API Key。
3
调用 API
在请求头中添加 API Key 即可开始调用。
API 调用示例
使用 X-API-Key 请求头进行认证。以下是 cURL、JavaScript 和 Python 的调用示例。
cURL
curl -X GET "https://api.524900.xyz/v1/weather?city=beijing" \
-H "X-API-Key: your_api_key_here" \
-H "Content-Type: application/json" JavaScript
const res = await fetch("https://api.524900.xyz/v1/weather?city=beijing", {
headers: {
"X-API-Key": "your_api_key_here",
"Content-Type": "application/json",
},
});
const data = await res.json();
console.log(data); Python
import requests
response = requests.get(
"https://api.524900.xyz/v1/weather",
params={"city": "beijing"},
headers={
"X-API-Key": "your_api_key_here",
"Content-Type": "application/json",
},
)
print(response.json()) 认证说明
Free API Hub 使用基于 API Key 的认证方式。注册登录后,在开发者后台生成你的 API Key,并在每次调用时通过 X-API-Key 请求头传入。
- 在开发者后台生成 API Key。
- 在每次请求的 X-API-Key 头中传入。
- 妥善保管 API Key,切勿在前端代码中暴露。
header
X-API-Key: your_api_key_here
Content-Type: application/json 错误码说明
API 返回的常见 HTTP 状态码。
| 状态码 | 说明 |
|---|---|
| 200 | 请求成功 |
| 400 | 请求参数错误 |
| 401 | 未授权 - API Key 无效或缺失 |
| 403 | 禁止访问 - 拒绝访问 |
| 404 | 资源不存在 |
| 429 | 请求过于频繁 - 超出速率限制 |
| 500 | 服务器内部错误 |