栗次元

随机图片接口json参数文档

通过 URL 参数选择分类,随机返回图片链接,供开发者简易调用并部署在项目中。

单条随机 GET

返回指定分类的一条随机图片链接。

http://localhost:3000/json?pc

多条随机 GET

在分类参数后写数字,返回指定数量的随机图片链接。

http://localhost:3000/json?pc=3

参数说明

参数说明示例
分类名 pc, ai, aimp, bd, fj, fjmp, lai, moe, moemp, mp, tx, xhl, ys, ysmp
pc ai aimp bd fj fjmp lai moe moemp mp tx xhl ys ysmp
?pc
数量 给分类参数赋数字值,表示返回几条。不填写时默认返回 1 条。 ?pc=3

直接调用(302重定向) GET

直接访问分类路径,会 302 重定向到随机图片,可直接用于 <img> 标签的 src。

http://localhost:3000/pc
效果预览(点击刷新):

返回示例

单条随机返回格式:

{ "code": 200, "category": "pc", "count": 1, "data": { "id": "example", "link": "http://localhost:3000/images/pc/example.webp" } }

多条随机返回格式(data 为数组):

{ "code": 200, "category": "pc", "count": 3, "data": [ { "id": "001", "link": "http://localhost:3000/images/pc/001.webp", "category": "pc" }, { "id": "002", "link": "http://localhost:3000/images/pc/002.webp", "category": "pc" }, { "id": "003", "link": "http://localhost:3000/images/pc/003.webp", "category": "pc" } ] }

前端调用示例

JavaScript fetch 方式:

fetch('http://localhost:3000/json?pc') .then(r => r.json()) .then(res => { console.log(res.data.link); // 直接用在 img 标签上 // img.src = res.data.link; });

HTML 直接引用(最简单):

<img src="http://localhost:3000/pc" alt="随机图片">