需要认证的端点需要在请求头中包含:
Authorization: Bearer your-secret-api-key-123
生产环境中请使用更安全的认证方式,如 JWT Token 或 OAuth 2.0
{
"status": "healthy",
"timestamp": "ISO8601",
"uptime": "online"
}
curl https://myservers.codelover.us.kg/api/health
{
"success": true,
"data": [],
"total": 0
}
curl -H "Authorization: Bearer your-secret-api-key-123" https://myservers.codelover.us.kg/api/users
:id - 用户ID{
"success": true,
"data": {}
}
curl -H "Authorization: Bearer your-secret-api-key-123" https://myservers.codelover.us.kg/api/users/:id
{
"name": "用户名",
"email": "email@example.com",
"role": "user"
}
{
"success": true,
"message": "用户创建成功",
"data": {}
}
curl -H "Authorization: Bearer your-secret-api-key-123" https://myservers.codelover.us.kg/api/users -X POST -H "Content-Type: application/json" -d '{"name":"用户名","email":"email@example.com","role":"user"}'
:id - 用户ID{
"name": "新名称",
"email": "newemail@example.com"
}
{
"success": true,
"message": "用户更新成功",
"data": {}
}
curl -H "Authorization: Bearer your-secret-api-key-123" https://myservers.codelover.us.kg/api/users/:id -X PUT -H "Content-Type: application/json" -d '{"name":"新名称","email":"newemail@example.com"}'
:id - 用户ID{
"success": true,
"message": "用户删除成功"
}
curl -H "Authorization: Bearer your-secret-api-key-123" https://myservers.codelover.us.kg/api/users/:id
page - 页码(默认1)limit - 每页数量(默认10){
"success": true,
"data": [],
"pagination": {}
}
curl https://myservers.codelover.us.kg/api/posts
:id - 文章ID{
"success": true,
"data": {
"author": {}
}
}
curl https://myservers.codelover.us.kg/api/posts/:id
{
"userId": 1,
"title": "文章标题",
"content": "文章内容"
}
{
"success": true,
"message": "文章创建成功",
"data": {}
}
curl -H "Authorization: Bearer your-secret-api-key-123" https://myservers.codelover.us.kg/api/posts -X POST -H "Content-Type: application/json" -d '{"userId":1,"title":"文章标题","content":"文章内容"}'
:id - 文章ID{
"title": "新标题",
"content": "新内容"
}
{
"success": true,
"message": "文章更新成功",
"data": {}
}
curl -H "Authorization: Bearer your-secret-api-key-123" https://myservers.codelover.us.kg/api/posts/:id -X PUT -H "Content-Type: application/json" -d '{"title":"新标题","content":"新内容"}'
:id - 文章ID{
"success": true,
"message": "文章删除成功"
}
curl -H "Authorization: Bearer your-secret-api-key-123" https://myservers.codelover.us.kg/api/posts/:id
q - 搜索关键词{
"success": true,
"query": "",
"results": {
"posts": [],
"users": []
},
"total": 0
}
curl https://myservers.codelover.us.kg/api/search
// JavaScript 示例
// 获取所有文章
const posts = await fetch('https://myservers.codelover.us.kg/api/posts')
.then(res => res.json());
// 创建用户(需要认证)
const newUser = await fetch('https://myservers.codelover.us.kg/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your-secret-api-key-123'
},
body: JSON.stringify({
name: '王五',
email: 'wangwu@example.com',
role: 'user'
})
}).then(res => res.json());