我看过很多关于 REST 的 SO 答案,但这个概念仍然不清楚。
至少,在我看来,正确命名(URL)是 REST 的核心。
如何使我的地址方案低于宁静?
(我有图像列表,但对于每个请求,我都会展示它们的不同子集)
image_list/recent (all image sorted in descending)
image_list/recent/front/ (to request newer images than a client has. client will provide the latest image id he has)
image_list/popular (sorted in popularity)
image_list/following/ (list of images of users that a client follows)
image_list/user_like/ (list of images a client likes)
当您有许多可以对资源执行的操作时怎么样?
image/upload/
image/delete/
image/like/
image/dislike/
image/hide/
编辑
这是查看答案后的解决方案。(但我仍然有疑问并确实表示过)
第一组
images/?mode=recent
images/?mode=recent_front
images/?mode=popular
images/?mode=following&user_id=3
images/?mode=like&user_id=3
images/ for all images
即使all images set
不断变化,这不是使用约定吗?
那我为什么不能用images/recent
呢?
第二套
images/ POST (to create)
images/ DELETE
(to delete, ok but I have not seen anyone using `DELETE`. Does anyone use it?)
images/3/like POST (OK there's a `like` DB entity)
images/3/dislike POST (umm but there's no dislike DB entity)
images/3/hide .. (there's no hide entity, it's a merely a field on image)