3分钟搞定!用 VPS 伪造 API 难道还不会? | 3‑Minute Hack: Faking APIs Like a Pro😂
搭建一个免费、本地、可控的“网络 + Mock API + Python 小实验室”,用 v2rayN/sing-box 管理网络环境,用本地 Fake/Mock API 做开发测试。
以前折腾网络和接口,像同时修路、修水管、还要猜服务器心情。现在 v2rayN + 本地 Mock API + Python 像自带迷你实验室:网络自己管,接口自己造,数据自己演。免费、可控、离线友好。小缺点?本地服务偶尔也会“罢工”,但至少这次老板就是你 😂
Networking and APIs used to feel like fixing roads, plumbing, and server moods at once. Now v2rayN + local Mock API + Python feels like owning a mini lab: control the network, fake the backend, test freely, and stay local. Mostly smooth—though local servers sometimes take coffee breaks too 😂
本地天气 API 实验室(Fake Weather API Lab)
Local Fake Weather API Lab - 免费本地 Mock API 开发小实验这是一个免费、本地、可控的网络 + Mock API + Python 小实验室。通过 v2rayN/sing-box 管理网络环境,用本地 Fake API 进行开发测试。
Step 1. 安装基础工具 / Install Basic Tools做什么? / What to do?
安装实验所需的核心工具。 / Install local tools.Mac 操作: / Mac Commands:
python3 --version
git --versionWindows 用户请前往官网下载安装 Python 和 Git。 / Windows users please download Python and Git from official websites.
Step 2. 安装 v2rayN / sing-box / Install v2rayN or sing-box做什么? / What to do?
安装网络客户端,用于模拟真实网络开发环境。 / Install network client.作用: / Purpose:
不是为了翻墙,而是模拟真实网络环境(DNS、路由、代理切换),让本地实验更接近真实开发场景。 / Not for bypassing firewall, but to simulate real network environment (DNS, routing, proxy switching).支持平台: / Supported Platforms:
Mac / Linux / Windows 全部支持。 / Fully supported on Mac / Linux / Windows.下载地址: / Download Links:
v2rayN(Windows 推荐):https://github.com/2dust/v2rayN
sing-box(跨平台推荐):https://github.com/sing-box/sing-box
Step 3. 创建项目文件夹 / Create Project Folder做什么? / What to do?
建立实验工作目录。 / Create workspace.命令: / Commands:
mkdir ~/fake_api_lab
cd ~/fake_api_lab项目结构: / Project Structure:
fake_api_lab/
├── weather.json
├── server.py
Step 4. 准备 Fake API 数据 / Prepare Mock API Data做什么? / What to do?
创建模拟天气数据。 / Mock API data.新建文件 weather.json,内容如下: / Create weather.json with the following content:{
"city": "Sydney",
"temp": 22,
"condition": "Sunny",
"humidity": 65,
"wind": "12 km/h"
}
Step 5. 编写并启动本地 Fake Backend / Run Local Fake Backend这是本实验核心。 / This is the core of the lab.做什么? / What to do?
用 Python 启动一个本地天气 API 服务器。 / Run local backend server.新建文件 server.py,内容如下: / Create server.py with the following code:from http.server import BaseHTTPRequestHandler, HTTPServer
import json class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/weather":
with open("weather.json", encoding="utf-8") as f:
data = json.load(f)
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(json.dumps(data).encode())
else:
self.send_response(404)
self.end_headers() server = HTTPServer(("localhost", 8000), Handler)
print("Fake Weather API 正在运行... http://localhost:8000/weather")
server.serve_forever()启动命令: / Run Command:
python3 server.py
Step 6. 测试本地 Fake API / Test Fake Backend测试命令: / Test Command:
curl http://localhost:8000/weather预期返回结果: / Expected Result:{"city":"Sydney", "temp":22, "condition":"Sunny", "humidity":65, "wind":"12 km/h"}v2rayN / sing-box 在本实验中的作用 / Role of v2rayN or sing-box作用: / Purpose:
不是必须,但非常有用。 / Not mandatory but very useful.它可以: / It can: 模拟真实网络环境(不同地区、不同出口 IP) / Simulate real network environment (different regions and exit IPs)
Step 7. 测试 DNS 解析、路由规则对 API 请求的影响 / Test DNS and routing effects on API calls
练习在不同网络环境下调用本地或远程 API / Practice calling APIs under different network conditions
为后续更复杂的本地实验打好基础 / Build foundation for advanced local experiments
Step 8. 实验完成提示: / Lab Tips: 保持 python3 server.py 窗口一直运行 / Keep the python3 server.py window running
可随时修改 weather.json 文件来模拟不同天气数据 / Modify weather.json anytime to simulate different weather
用 v2rayN 切换不同节点后重新执行 curl 命令,观察返回结果是否变化 / Switch nodes in v2rayN and re-test with curl to see differences
相关链接(Related links):
https://github.com/2dust/v2rayN
https://github.com/2dust/v2rayN/releases
https://github.com/XTLS/Xray-core
https://github.com/SagerNet/sing-box
https://python.org
https://git-scm.com
https://github.com/typicode/json-server
https://mockoon.com
https://github.com/manjeyy/mocktopus
https://v2rayn.xyz/en/
https://subconverters.com/clash-to-v2ray https://sub.v1.mk/ https://acl4ssr-sub.github.io/ https://www.ip2free.com/cn https://ikuuu.org/auth/login https://tempail.com/en/ https://scamalytics.com/
Comments
Post a Comment