REST Countries
通过 RESTful API 获取国家信息
- 认证方式
- No auth
- HTTPS
- Yes
- CORS
- Yes
- 分类
- 地理编码
- 文档 / URL
- https://restcountries.com
简介
REST Countries 提供全球各国的结构化数据——多语言国名、ISO 代码、货币、语言、首都、国旗、区域划分等。多年来一直是免费开发者工具的主力,非常适合国家选择器、数据面板和本地化功能。
⚠️ 状态更新(2026-08 实测):经典的
v3.1接口已弃用。请求现在会重定向到弃用提示,新的 v5 接口需要 API 密钥(在官网免费注册)。上方收录信息仍标记为免认证——那反映的是旧版状态。动手开发前请查看官方迁移指南。
提供的数据
- 国家列表:国名、ISO 3166 代码(alpha-2/alpha-3)、电话区号
- 货币、语言、首都、人口、面积、时区
- 国旗(SVG/PNG)与国徽 URL
- 地区分组(region/subregion)
- 按名称、代码、货币、语言、首都、地区搜索
旧版快速开始(v3.1 —— 已弃用)
curl "https://restcountries.com/v3.1/name/china"
curl "https://restcountries.com/v3.1/alpha/US"
curl "https://restcountries.com/v3.1/all"
这些请求现在会重定向到弃用提示——请迁移到 v5。
迁移说明(v5)
- 新接口基址:
api.restcountries.com(以官方文档为准)。 - 需要 API 密钥——在 restcountries.com 免费注册。
- 具体请求格式与响应结构变化,请按官方弃用指南迁移。
常见问题
REST Countries 还免费吗? 旧版 v3.1 免费且免密钥,但已弃用;替代的 v5 需要(免费)API 密钥——以官网最新条款为准。
为什么我的 v3.1 请求突然失效了? 旧版接口已弃用,请求返回迁移提示。请按官方弃用指南切换到 v5。
可以在浏览器直接调用吗? 旧版支持 CORS;v5 的 CORS 行为请查阅新版文档。
地理编码 分类更多
| API | Auth | HTTPS | CORS | |
|---|---|---|---|---|
| Actinia Grass GIS Actinia is an open source REST API for geographical data that uses GRASS GIS | API Key | Yes | Unknown | ↗ |
| administrative-divisons-db Get all administrative divisions of a country | No auth | Yes | Yes | ↗ |
| adresse.data.gouv.fr Address database of France, geocoding and reverse | No auth | Yes | Unknown | ↗ |
| Airtel IP IP Geolocation API. Collecting data from multiple sources | No auth | Yes | Unknown | ↗ |
| Apiip Get location information by IP address | API Key | Yes | Yes | ↗ |