接入教程
GET https://www.dnd5eapi.co/api/classes1. 获取职业列表:
2. 获取职业详情:/api/classes/wizard。
3. 法术:/api/spells。
4. 怪物:/api/monsters。
5. 返回JSON,包含索引、名称、能力等字段。
Python 获取法术列表
python
import requests
r = requests.get("https://www.dnd5eapi.co/api/spells")
count = r.json()["count"]
print(count, "spells")
PHP 获取职业详情
php
<?php
$d = json_decode(file_get_contents("https://www.dnd5eapi.co/api/classes/wizard"), true);
echo $d["name"] . " hit dice: d" . $d["hit_die"];
JavaScript 获取怪物列表
javascript
const d = await fetch("https://www.dnd5eapi.co/api/monsters").then(r => r.json());
console.log(d.count, "monsters");
常见问题
需要密钥吗?
不需要,完全免费开放。
包含哪些数据?
职业、法术、怪物、种族、背景、装备等官方SRD内容。
Aitishiku.com