- URL:
POST /api/users
- Content-Type:
application/json
{
"name": "张三",
"email": "zhangsan@example.com",
"phone": "13800138000",
"avatar": "https://example.com/avatar.jpg",
"status": "active"
}
name: 用户名(字符串)
email: 邮箱地址(字符串,需要符合邮箱格式)
phone: 手机号(字符串)
avatar: 头像URL(字符串)
status: 用户状态(字符串,默认为"active")
{
"code": 0,
"data": {
"id": 1703123456789,
"name": "张三",
"email": "zhangsan@example.com",
"phone": "13800138000",
"avatar": "https://example.com/avatar.jpg",
"status": "active",
"createTime": "2023-12-21T10:30:45.123Z",
"updateTime": "2023-12-21T10:30:45.123Z"
},
"message": "用户创建成功"
}
{
"code": 400,
"error": "用户名和邮箱是必填项",
"message": "参数错误"
}
{
"code": 400,
"error": "邮箱格式不正确",
"message": "参数错误"
}
{
"code": 500,
"error": "创建用户失败",
"message": "服务器内部错误"
}
curl -X POST http://localhost:7001/api/users \
-H "Content-Type: application/json" \
-d '{
"name": "张三",
"email": "zhangsan@example.com",
"phone": "13800138000"
}'
const response = await fetch('/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: '张三',
email: 'zhangsan@example.com',
phone: '13800138000'
})
});
const result = await response.json();
console.log(result);
- 选择POST方法
- 输入URL:
http://localhost:7001/api/users
- 在Headers中添加:
Content-Type: application/json
- 在Body中选择raw,格式选择JSON
- 输入请求体数据
- 点击Send发送请求