-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiTester.http
More file actions
234 lines (178 loc) · 6.29 KB
/
Copy pathapiTester.http
File metadata and controls
234 lines (178 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
### ============================================
### Luhanxin Community — API 测试文件
### 使用 VS Code REST Client 插件直接运行
### 启动后端: make dev-backend
### ============================================
@baseUrl = http://localhost:8000
@contentType = application/json
### ──────────── 系统 ────────────
### 健康检查
GET {{baseUrl}}/health
### ──────────── 认证(公开)────────────
### 用户注册
POST {{baseUrl}}/api/v1/auth/register
Content-Type: {{contentType}}
{
"username": "alice",
"email": "alice@example.com",
"password": "Pass1234"
}
### 用户登录(保存 token 供后续使用)
# @name login
POST {{baseUrl}}/api/v1/auth/login
Content-Type: {{contentType}}
{
"username": "alice",
"password": "Pass1234"
}
### ──────────── 认证(需 Token)────────────
### 获取当前用户
GET {{baseUrl}}/api/v1/auth/me
Authorization: Bearer {{login.response.body.token}}
### 更新用户资料(全量覆盖,含社交链接)
PUT {{baseUrl}}/api/v1/auth/profile
Content-Type: {{contentType}}
Authorization: Bearer {{login.response.body.token}}
{
"display_name": "Alice Updated",
"avatar_url": "",
"bio": "Hello from REST Client! 🚀",
"company": "Luhanxin Inc.",
"location": "Beijing, China",
"website": "https://luhanxin.com",
"social_links": [
{ "platform": "github", "url": "https://github.com/alice" },
{ "platform": "twitter", "url": "https://x.com/alice" },
{ "platform": "juejin", "url": "https://juejin.cn/user/alice" }
]
}
### ──────────── 用户查询(公开)────────────
### 按 ID 查询用户(替换为实际 UUID)
GET {{baseUrl}}/api/v1/users/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
### 按用户名查询用户
GET {{baseUrl}}/api/v1/users/by-username/luhanxin
### 用户列表(默认)
GET {{baseUrl}}/api/v1/users
### 用户列表(搜索 + 分页)
GET {{baseUrl}}/api/v1/users?query=lu&page_size=5
### ──────────── 错误场景 ────────────
### 登录错误密码 → 401
POST {{baseUrl}}/api/v1/auth/login
Content-Type: {{contentType}}
{
"username": "alice",
"password": "WrongPass1"
}
### 注册重复用户名 → 409
POST {{baseUrl}}/api/v1/auth/register
Content-Type: {{contentType}}
{
"username": "alice",
"email": "alice2@example.com",
"password": "Pass1234"
}
### 无 token 访问需认证端点 → 401
GET {{baseUrl}}/api/v1/auth/me
### 更新资料无 token → 401
PUT {{baseUrl}}/api/v1/auth/profile
Content-Type: {{contentType}}
{
"display_name": "Hacker"
}
### 查询不存在的用户 → 404
GET {{baseUrl}}/api/v1/users/00000000-0000-0000-0000-000000000000
### 无效 UUID → 400
GET {{baseUrl}}/api/v1/users/not-a-uuid
### 按用户名查不存在 → 404
GET {{baseUrl}}/api/v1/users/by-username/nobody
### 密码太短 → 400
POST {{baseUrl}}/api/v1/auth/register
Content-Type: {{contentType}}
{
"username": "bob",
"email": "bob@example.com",
"password": "short"
}
### 用户名太短 → 400
POST {{baseUrl}}/api/v1/auth/register
Content-Type: {{contentType}}
{
"username": "ab",
"email": "ab@example.com",
"password": "Pass1234"
}
### ──────────── 文章(公开)────────────
### 文章列表(默认,已发布文章)
GET {{baseUrl}}/api/v1/articles
### 文章列表(分页)
GET {{baseUrl}}/api/v1/articles?page_size=5
### 文章列表(按作者筛选)
GET {{baseUrl}}/api/v1/articles?author_id=a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
### 文章列表(标题搜索)
GET {{baseUrl}}/api/v1/articles?query=rust
### 文章列表(按标签筛选)
GET {{baseUrl}}/api/v1/articles?tag=rust
### 获取文章详情(替换为实际 article_id)
GET {{baseUrl}}/api/v1/articles/00000000-0000-0000-0000-000000000001
### ──────────── 文章(需 Token)────────────
### 创建文章(草稿)
# @name createArticle
POST {{baseUrl}}/api/v1/articles
Content-Type: {{contentType}}
Authorization: Bearer {{login.response.body.token}}
{
"title": "Rust 异步编程入门",
"content": "## 前言\n\nRust 的异步编程模型基于 Future trait...\n\n### tokio\n\n```rust\n#[tokio::main]\nasync fn main() {\n println!(\"Hello async!\");\n}\n```\n\n这是一篇测试文章,用于验证文章 CRUD 功能。",
"tags": ["rust", "async", "tokio"],
"status": 1
}
### 创建文章(直接发布)
POST {{baseUrl}}/api/v1/articles
Content-Type: {{contentType}}
Authorization: Bearer {{login.response.body.token}}
{
"title": "前端微服务架构实践",
"content": "## 微前端\n\n微前端是一种将单体前端应用拆分为多个独立子应用的架构模式。\n\n### Garfish\n\nGarfish 是字节跳动开源的微前端框架...",
"summary": "微前端架构的实践经验分享,包括 Garfish 框架的使用",
"tags": ["frontend", "micro-frontend", "garfish"],
"status": 2
}
### 更新文章(改标题 + 发布)
PUT {{baseUrl}}/api/v1/articles/{{createArticle.response.body.article.id}}
Content-Type: {{contentType}}
Authorization: Bearer {{login.response.body.token}}
{
"title": "Rust 异步编程完全指南(更新版)",
"status": 2
}
### 删除文章(软删除 → ARCHIVED)
DELETE {{baseUrl}}/api/v1/articles/{{createArticle.response.body.article.id}}
Authorization: Bearer {{login.response.body.token}}
### ──────────── 文章错误场景 ────────────
### 无 token 创建文章 → 401
POST {{baseUrl}}/api/v1/articles
Content-Type: {{contentType}}
{
"title": "Should fail",
"content": "No auth"
}
### 获取不存在的文章 → 404
GET {{baseUrl}}/api/v1/articles/00000000-0000-0000-0000-000000000000
### 无效 UUID → 400
GET {{baseUrl}}/api/v1/articles/not-a-uuid
### 创建文章缺少标题 → 400
POST {{baseUrl}}/api/v1/articles
Content-Type: {{contentType}}
Authorization: Bearer {{login.response.body.token}}
{
"title": "",
"content": "Missing title"
}
### 创建文章缺少内容 → 400
POST {{baseUrl}}/api/v1/articles
Content-Type: {{contentType}}
Authorization: Bearer {{login.response.body.token}}
{
"title": "No content",
"content": ""
}