惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
GbyAI
GbyAI
I
InfoQ
C
Cisco Blogs
T
Tor Project blog
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
H
Help Net Security
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
A
Arctic Wolf
Stack Overflow Blog
Stack Overflow Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Palo Alto Networks Blog
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
P
Privacy International News Feed
L
LINUX DO - 热门话题
Know Your Adversary
Know Your Adversary
L
LangChain Blog
AWS News Blog
AWS News Blog
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
U
Unit 42
P
Privacy & Cybersecurity Law Blog
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
Latest news
Latest news
L
Lohrmann on Cybersecurity
小众软件
小众软件
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
雷峰网
雷峰网
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
S
SegmentFault 最新的问题
Recent Announcements
Recent Announcements
C
Cybersecurity and Infrastructure Security Agency CISA
Martin Fowler
Martin Fowler
S
Schneier on Security
C
CERT Recently Published Vulnerability Notes
B
Blog
Project Zero
Project Zero
Recorded Future
Recorded Future

博客园 - 丁少华

React UI 库推荐 Loop Engineering Vue 3 UI 组件库 Neon白嫖免费pgsql 域名利用cloudflare免费图床 nginx反代CloudflarePages提示502 vite使用shadcn vite使用biome Window下Nginx winserver2022安装不上软件 mac已损坏无法打开 代码高亮 命令运行器之task 命令运行器之just windows开启wsl 白嫖Redis 白嫖MongoDB vercel无服务函数 无服务器函数完全指南 解释型语言和编译型语言 何时该使用monorepo monorepo前端专属吗 Cursor锁区问题 CentOS9上Let’s Encrypt自动续签 Windows给文件夹别名 ai 常识 nestjs逆向工程Prisma与DTO nestjs的orm之Prisma
在线 mock 方案
丁少华 · 2026-01-06 · via 博客园 - 丁少华

1. My JSON Server(目前最稳定)

GitHub + 免费托管,完美符合你的需求:

使用方法:

  1. 创建 GitHub 仓库(例如:my-mock-api
  2. 添加 db.json 文件到仓库
  3. 访问 API
    https://my-json-server.typicode.com/你的用户名/仓库名
    

示例:

// 你的 db.json 文件内容
{
  "users": [
    { "id": 1, "name": "张三", "email": "zhang@test.com" },
    { "id": 2, "name": "李四", "email": "li@test.com" }
  ],
  "posts": [
    { "id": 1, "title": "文章1", "authorId": 1 },
    { "id": 2, "title": "文章2", "authorId": 2 }
  ]
}

访问地址:

GET    https://my-json-server.typicode.com/username/repo/users
GET    https://my-json-server.typicode.com/username/repo/users/1
POST   https://my-json-server.typicode.com/username/repo/users
PUT    https://my-json-server.typicode.com/username/repo/users/1
DELETE https://my-json-server.typicode.com/username/repo/users/1

特点:

  • ✅ 完全免费
  • ✅ 支持真实 CRUD(数据会变,但不是永久存储)
  • ✅ 无需服务器
  • ✅ 基于 GitHub,版本可控

2. MockAPI.io

网址: https://mockapi.io/

特点:

  • 可视化创建 API
  • 支持完整的 CRUD
  • 可以设置响应格式
  • 有免费套餐(每月 10000 次请求)

创建步骤:

  1. 注册账号
  2. 点击 "New Project"
  3. 创建 Resource(如 users
  4. 手写 JSON 或使用表单添加
  5. 获得 API 端点

示例端点:

https://64d8f6e25f9bf5b879cea5c2.mockapi.io/api/v1/users

3. DummyJSON

网址: https://dummyjson.com/

虽然主要提供预定义数据,但支持修改:

// 更新数据示例
fetch('https://dummyjson.com/users/1', {
  method: 'PUT',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    name: '修改后的名字'
  })
})

4. ReqRes.in

网址: https://reqres.in/

主要用于测试,支持 CRUD:

POST   https://reqres.in/api/users
PUT    https://reqres.in/api/users/2
DELETE https://reqres.in/api/users/2

5. JSONBin.io

网址: https://jsonbin.io/

专门为 JSON 设计的在线存储:

创建步骤:

  1. 创建 bin
  2. 手写 JSON 数据
  3. 获得 API 密钥
  4. 使用 REST API 访问
// 创建 bin
fetch('https://api.jsonbin.io/v3/b', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Master-Key': '$2a$10$...'
  },
  body: JSON.stringify({
    users: [
      { id: 1, name: "张三" }
    ]
  })
})

6. RapidAPI(多个提供商)

网址: https://rapidapi.com/hub

搜索 "mock api" 有很多服务商,部分支持自定义数据。

7. 部署到免费云平台(最灵活)

Vercel + JSON Server

  1. 创建 GitHub 仓库
  2. 添加 api/index.js
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();

server.use(middlewares);
server.use(router);

module.exports = server;
  1. 部署到 Vercel(免费)

GitHub Pages + JSON Server

需要一些配置,但完全免费。

对比推荐

服务 手写JSON 真实CRUD 免费额度 推荐指数
My JSON Server ⚠️(临时) 无限制 ⭐⭐⭐⭐⭐
MockAPI.io 10k/月 ⭐⭐⭐⭐
JSONBin.io 有限 ⭐⭐⭐⭐
ReqRes.in 无限制 ⭐⭐⭐
RapidAPI 看提供商 看提供商 各不相同 ⭐⭐

最佳实践方案

方案A:快速开始(推荐)

  1. 使用 My JSON Server
  2. 在 GitHub 创建 db.json
  3. 通过 typicode 访问
  4. 更新数据时 push 到 GitHub

方案B:长期项目

  1. 使用 MockAPI.io
  2. 创建免费账号
  3. 通过界面管理数据
  4. 使用提供的 API 端点

方案C:需要复杂逻辑

  1. 部署到 Vercel
  2. 使用 JSON Server 或自定义 Express
  3. 获得完全控制权

具体操作示例(My JSON Server)

  1. 创建 GitHub 仓库my-mock-data
  2. 创建 db.json
{
  "products": [
    {
      "id": 1,
      "name": "iPhone 14",
      "price": 6999,
      "category": "手机"
    },
    {
      "id": 2,
      "name": "MacBook Pro",
      "price": 12999,
      "category": "电脑"
    }
  ],
  "categories": [
    { "id": 1, "name": "手机" },
    { "id": 2, "name": "电脑" }
  ]
}
  1. 访问 API
# 获取所有商品
curl https://my-json-server.typicode.com/你的用户名/my-mock-data/products

# 获取单个商品
curl https://my-json-server.typicode.com/你的用户名/my-mock-data/products/1

# 创建商品(临时)
curl -X POST https://my-json-server.typicode.com/你的用户名/my-mock-data/products \
  -H "Content-Type: application/json" \
  -d '{"id":3,"name":"iPad","price":4999}'

# 分页和过滤
curl "https://my-json-server.typicode.com/你的用户名/my-mock-data/products?price_gte=5000"

注意:POST/PUT/DELETE 操作会修改数据,但这些修改不会保存到 GitHub,只是临时的内存修改。

紧急备用方案

如果以上都不行,可以用这个临时在线 JSON:

// 使用这个公开的测试端点(可能有访问限制)
fetch('https://httpbin.org/anything', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: '测试数据' })
})
.then(res => res.json())
.then(data => console.log(data.json)); // 会返回你发送的数据

推荐:直接使用 My JSON Server,这是最接近你需求的方案!