【发布时间】:2016-05-31 12:28:52
【问题描述】:
我的实体名为Item。
POST /api/items create a new Item
PUT /api/items/{id} update an existing Item
GET /api/items/{id} get Item by id
但是,我需要以三种不同的模式检索项目:最近的(按纬度、经度和距离)、Favorite(由 isFavorite 标志标记)和 个人(由用户插入)。
虽然我可以命名这三个 URL:
GET /api/items/nearest?latitude=xxx&longitude=xxx&distance=xxx
GET /api/items/favorite
GET /api/items/personal
但是当我读到这可能违反 REST 命名约定时。我应该使用类型参数(某种枚举)吗?但是这样用户就可以调用GET /api/items?type=favorite&latitude=xxx&longitude=xxx&distance=xxx,这是没有意义的。
最后一个问题:Twitter API 似乎不遵守 REST 命名约定,端点像 POST statuses/update 或 GET direct_messages/sent。你怎么看?
【问题讨论】:
标签: web-services api rest asp.net-web-api2 restful-url