Node 本地 Mock 服务 · 内存存储 · 合成练习数据 · 监听 127.0.0.1:8281
| 方法 | 路径 | 说明 | 成功 | 错误 |
|---|---|---|---|---|
| GET | /items |
获取条目列表 | 200 | — |
| GET | /items/{id} |
获取单个条目 | 200 | 400 非法 id · 404 不存在 |
| POST | /items |
创建条目(name 非空、quantity 正整数) | 201 | 400 非法 · 413 超 64KB · 415 非 JSON 类型 |
请求体上限 64KB;拒绝非 JSON 与非法字段;POST 只接受 application/json。
本地打开本页即可使用;若提示无法连接,请先在终端运行 node server.js。
前端会先行校验:name 为空或 quantity 非正整数时会就地提示;服务的 400/404/413/415 也在此显示。
尚未请求
# 1) 获取列表
curl -sS http://127.0.0.1:8281/items
# 2) 获取单个(不存在返回 404)
curl -sS http://127.0.0.1:8281/items/1
# 3) 创建条目(成功 201)
curl -sS -X POST http://127.0.0.1:8281/items \
-H 'Content-Type: application/json' \
--data '{"name":"橡皮","quantity":5}'
# 4) 非法字段(400)
curl -sS -X POST http://127.0.0.1:8281/items \
-H 'Content-Type: application/json' \
--data '{"name":"x","quantity":1,"extra":true}'
更完整示例(含 400/404/413/415/405)见 curl-examples.sh。