数据列表
请填写服务器地址与 API Key,点击「验证并加载」
编辑数据
操作结果
等待操作...
等待操作...
baseUrl 会与页面顶部「服务器地址」同步(未填且通过 http(s) 打开本页时为当前页的协议+主机+端口);apikey 请换成你的密钥。认证:查询参数 ?apikey= 或请求头 x-api-key。GET /configInfo 校验 Key 并返回配置摘要(不含密钥原文)。const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(
`${baseUrl}/configInfo?apikey=${encodeURIComponent(apikey)}`,
{ method: 'GET' }
);
const result = await res.json();
// result.success === true 时:result.config 含 name、expireDate、maxMb、canUse、dataType
console.log(result);
_id;新增时若省略 _id 会自动生成。page、pageSize,最大 500);full=1 时返回全量数组。字段名=值 精确;字段名_like=片段 模糊(不分大小写);字段名_gt / _gte / _lt / _lte 比较(优先按数值,其次按日期,否则字符串)。字段名含后缀歧义时可用 字段_eq 表示精确。sort=字段名升序,sort=-字段名降序;多字段可用逗号分隔。POST /save:提交对象追加一条;提交数组则批量追加。POST /update:Body 必须含 _id,与服务端记录合并。POST /delete:Body 为 { "_id": "..." }。POST /coverSave:Body 为完整数组,替换整个文件(未带 _id 的项会自动补 _id)。默认 pageSize 20,返回 data、total、page、totalPages。
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(
`${baseUrl}/query?apikey=${encodeURIComponent(apikey)}&page=1&pageSize=20`,
{ method: 'GET' }
);
const result = await res.json();
// result.success === true 时:result.data 当前页,result.total 总条数
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const sortField = 'createdAt';
const sortDesc = true; // true 降序,false 升序
const sort = encodeURIComponent(sortDesc ? `-${sortField}` : sortField);
const res = await fetch(
`${baseUrl}/query?apikey=${encodeURIComponent(apikey)}&page=1&pageSize=20&sort=${sort}`,
{ method: 'GET' }
);
const result = await res.json();
console.log(result);
可与分页、排序组合;多个查询参数之间为 AND。
const baseUrl = '';
const apikey = '你的_apikey';
const q =
`${baseUrl}/query?apikey=${encodeURIComponent(apikey)}` +
'&page=1&pageSize=20' +
`&${encodeURIComponent('name')}=${encodeURIComponent('张三')}` +
`&${encodeURIComponent('title_like')}=${encodeURIComponent('实习')}` +
`&${encodeURIComponent('age_gte')}=${encodeURIComponent('18')}`;
const res = await fetch(q, { method: 'GET' });
const result = await res.json();
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(
`${baseUrl}/query?apikey=${encodeURIComponent(apikey)}&full=1`,
{ method: 'GET' }
);
const result = await res.json();
// result.data 为完整数组,result.total 为长度
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/save?apikey=${encodeURIComponent(apikey)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: '张三', age: 25 })
});
const result = await res.json();
// 服务端会为该项生成 _id 并写入文件
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/save?apikey=${encodeURIComponent(apikey)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify([
{ name: 'A', score: 1 },
{ name: 'B', score: 2 }
])
});
const result = await res.json();
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/update?apikey=${encodeURIComponent(apikey)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
_id: '已有记录的_id',
name: '李四',
age: 30
})
});
const result = await res.json();
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/delete?apikey=${encodeURIComponent(apikey)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ _id: '要删除的_id' })
});
const result = await res.json();
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/coverSave?apikey=${encodeURIComponent(apikey)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify([
{ _id: '可选保留原id', name: '整条数据替换' }
])
});
const result = await res.json();
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/query?page=1&pageSize=20`, {
method: 'GET',
headers: { 'x-api-key': apikey }
});
const result = await res.json();
console.log(result);
baseUrl 同步规则同数组页;apikey 换为实际值。对象类型为单个 JSON 对象。可先 GET /configInfo 确认 dataType 为 object。const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(
`${baseUrl}/configInfo?apikey=${encodeURIComponent(apikey)}`,
{ method: 'GET' }
);
const result = await res.json();
// result.success === true 时:result.config 含 name、expireDate、maxMb、canUse、dataType
console.log(result);
GET /query:一次返回整个对象 result.data,无分页参数。POST /save:Body 为对象,与磁盘上的对象做 Object.assign,相同键覆盖。POST /update:Body 必须为 { "key": "字段名", "value": 任意JSON可序列化值 }。POST /delete:Body 为 { "key": "字段名" }。POST /coverSave:Body 为完整对象,替换整个文件。const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(
`${baseUrl}/query?apikey=${encodeURIComponent(apikey)}`,
{ method: 'GET' }
);
const result = await res.json();
// result.success === true 时 result.data 即为对象
console.log(result.data);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/save?apikey=${encodeURIComponent(apikey)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
theme: 'dark',
notify: true,
meta: { version: 1 }
})
});
const result = await res.json();
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/update?apikey=${encodeURIComponent(apikey)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
key: 'theme',
value: 'light'
})
});
const result = await res.json();
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/delete?apikey=${encodeURIComponent(apikey)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: 'theme' })
});
const result = await res.json();
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/coverSave?apikey=${encodeURIComponent(apikey)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
settingA: 1,
settingB: { nested: true }
})
});
const result = await res.json();
console.log(result);
const baseUrl = '';
const apikey = '你的_apikey';
const res = await fetch(`${baseUrl}/query`, {
method: 'GET',
headers: { 'x-api-key': apikey }
});
const result = await res.json();
console.log(result);
请输入 json-server.json 中的 adminPassword。验证成功后可用右上角「管理 API Key」编辑配置,或使用「快速选择」切换 Key。
修改后将直接写回服务端 json-server.json;不会删除 json-server-data 下已有数据文件。
| 存储名称 name | apikey | 过期 expireDate | maxMb | 启用 | 类型 | 操作 |
|---|
内容由服务端 GET /configInfo 校验返回;完整密钥仅保存在本页输入框与本机浏览器存储中,此处为脱敏展示。