随机地址生成 Web API · ← 返回主页
${location.origin}
返回所有支持的国家和地区分组。
响应示例:
{
"ok": true,
"countries": [
{ "code": "us", "name": "United States", "nameZh": "美国", "dial": "+1", "region": "americas" }
],
"regions": [
{ "id": "americas", "label": "美洲", "labelEn": "Americas" }
]
}
生成指定国家的随机真实地址。
| 参数 | 类型 | 说明 |
|---|---|---|
| country | string | 国家代码(如 us, jp, cn)必填 |
| count | number | 生成数量,1-20,默认 1可选 |
单条请求: GET /api/address?country=us
{
"ok": true,
"country": { "code": "us", "name": "United States", ... },
"address": {
"name": "James Wilson",
"street": "4518 Oak Avenue",
"city": "Portland",
"state": "Oregon",
"zip": "97201",
"phone": "+15031234567"
}
}
批量请求: GET /api/address?country=jp&count=3
{
"ok": true,
"country": { ... },
"addresses": [ { ... }, { ... }, { ... } ],
"count": 3
}
错误响应:
{
"ok": false,
"error": {
"code": "MISSING_COUNTRY",
"message": "请选择一个国家"
}
}
# 单条地址 curl -s "http://localhost:3000/api/address?country=us" | jq . # 批量获取 5 条日本地址 curl -s "http://localhost:3000/api/address?country=jp&count=5" | jq . # 获取所有国家 curl -s "http://localhost:3000/api/countries" | jq .countries[].code
| Code | HTTP | 说明 |
|---|---|---|
| MISSING_COUNTRY | 400 | 未提供 country 参数 |
| UNSUPPORTED_COUNTRY | 400 | 不支持的国家代码 |
| SESSION_UNAVAILABLE | 502 | 上游会话不可用 |
| FETCH_FAILED | 502 | 获取页面失败 |
| EMPTY_PAGE | 502 | 页面为空 |
| PARSE_FAILED | 502 | 解析地址失败 |
选择国家后点击「发送请求」