我们有一个应用程序,它分为两部分:
- 管理员 - 更改数据的位置
- 公共 - 读取数据的位置
我正在考虑创建一个 REST API 来提供此功能。很容易看出如何表示 CRUD 操作,但我不确定单个资源上的特定操作(命令)。例如,Project
我们发送一个“PublishCommand”来“发布”。我们不会将Project
其Published
属性设置为true
.
同样,我有点困惑,我们应该如何表示更高级的资源查询操作而不被归类为 RPC 类型服务。
下面我列出了我的Project
资源的 URI 模板。我是否走上了创建真正 RESTful API 的正确轨道?
ADMIN API
---------
// Project Resources
GET /projects -- get all projects
POST /projects -- create a new project
// Project Resource
GET /projects/10 -- get project with id 10
PUT /projects/10 -- update project with id 10
DELETE /projects/10 -- delete project with id 10
// Project Resource Operations
POST: /projects/10/publish -- publish project with id 10
POST: /projects/10/unpublish -- unpublish project with id 10
POST: /projects/10/setposition/2 -- move to position 2 in projects list
// Project Sub resources (identity is local to project)
POST: /projects/10/media -- adds media to project with id 10
PUT: /projects/10/media/5 -- updates media id 5 for project id 10
DELETE: /projects/10/media/5 -- deletes media id 5 from project id 10
PUBLIC API
----------
GET: /projects -- gets all projects (with default limit e.g. first 10)
GET: /projects?skip=10&take=10 -- gets projects 11 to 20
GET: /projects/tagged/rest OR /taggedprojects/rest -- gets projects tagged with "REST"
GET: /projects?orderbydesc=publishdate OR /latestprojects -- gets latest projects
GET: /projects/10 -- gets project with id 10