HTTP 请求 | 优点 | 缺点 | 得分 |
---|---|---|---|
GET /create/user?username={username} | 不需要思考 | 罄竹难书 | 1 |
GET /list/user/by-page/{pageNo} | |||
DEL /update/password |
HTTP 请求 | 优点 | 缺点 | 得分 |
---|---|---|---|
POST /createUser | 直观 | 日志统计麻烦 | 3 |
GET /readUser | LB 不方便 | ||
POST /updateUser | 过滤略繁琐 | ||
POST /deleteUser | |||
GET /listUsers | |||
GET /listPopularUsers | |||
GET /searchUsers | |||
POST /followUser | |||
POST /unfollowUser |
HTTP 请求 | 优点 | 缺点 | 得分 |
---|---|---|---|
POST /users/create | m2m | 4 | |
GET /users/{userId} | |||
POST /users/{userId}/update | |||
POST /users/{userId}/delete | |||
GET /users/ | |||
GET /users/popular | |||
GET /users/search?q={q} | |||
POST /users/{userId}/follow | |||
POST /users/{userId}/unfollow |
HTTP 请求 | 优点 | 缺点 | 得分 |
---|---|---|---|
POST /users | 满足强迫症 | m2m | 4 |
GET /users/{userId} | |||
PUT /users/{userId} | |||
DEL /users/{userId} | |||
GET /users | |||
GET /users/popular | |||
GET /users/search | |||
PUT /me/following/{userId} | |||
DEL /me/following/{userId} |
class Project {
int id;
String name;
Creator Creator; // id, name
}
{
Project(byid=20): Project
}
URL 表示资源
- 要么最后一个单词是实体
- 要么最后两个单词是 实体+修饰词(/posts/search, /me/followship/from-me, /me/followship/to-me)
- 和当前用户相关的信息,放入单独的 object 中
/posts?offset=290&limit=20
/posts?page=3&per_page=20
- 简单易懂,和 SQL 直接映射
- 能选择指定页
- 频繁变化的数据,可能出现重复、遗漏的情况
- 数据量大时有性能问题
/posts?cursor={cursor}
- 灵活,支持任意的分页方案
- 高性能
select * from posts where id < {postId}
- 不支持展示指定页的内容
{
"post": {
"id": 291029032,
"title": "这是一篇极好的文章",
"author": {
"id": 923092,
"username": "小明同学",
"user_relation": {
"is_blocked_by_me": true,
"is_followed_by_me": true,
"is_following_me": false
}
},
"post_relation": {
"is_editable": false,
"is_subscribed": false
}
}
}
POST /users/
POST /users/phonenumber
POST /users/wechat
POST /auth/register
POST /auth/register/phonenumber~
POST /auth/register/wechat
POST /tokens/
POST /tokens/phonenumber
POST /tokens/wechat
POST /auth/login
POST /auth/login/phonenumber
POST /auth/login/wechat
GET /posts/
GET /posts/popular
GET /posts/recent
GET /posts/search?q={q}
GET /categories/{cat}/posts
GET /tags/{cat}/posts
GET /posts/search?q={q}&cats={cat1,cat2}&tags={tag1,tag2}
高级查询
POST /posts/{postId}/subscribe
PUT /me/subscribing/{postId}
PUT /me/subscribing-posts/{postId}
GET /me/subscribing-posts
我的订阅GET /me/followers
我的关注GET /me/followees
我的粉丝
GET /me/subscribing
我的订阅GET /me/followships/from-me
我的关注GET /me/followships/to-me
我的粉丝GET /me/followships/incoming
我的关注(请求)GET /me/followships/outgoing
我的粉丝(请求)GET /me/following
我的关注GET /me/followed
我的粉丝