REST 中的许多类似资源 API

Many similar resources in REST API

我正在为多媒体服务开发 API。在数据库中,我有存储不同媒体(电影、音乐、连续剧等)的媒体 table。有两种类型的用户:管理员和用户。

用户可以使用不同的端点访问媒体:

每个端点returns只有特定于媒体类型的数据。每个端点都有特定的搜索参数。

API 管理员不会 public。创建单个端点来控制媒体类型是否正常?例如,我可以创建 /media 将用于 CRUD 不同媒体类型的端点。

我是否应该将不同项目中的管理员 API 和用户 API 分开?

当资源对管理员和用户有不同的字段时,我应该如何处理?

How should I handle situations when resource has different fields for admins and users?

Should I separate API for admins and API for users in different projects?

可能吧。记住资源“适应”您的网络领域模型可能会有所帮助——它们是一个集成问题。

The web is not your domain, it's a document management system. All the HTTP verbs apply to the document management domain. URIs do NOT map onto domain objects - that violates encapsulation. Work (ex: issuing commands to the domain model) is a side effect of managing resources. In other words, the resources are part of the anti-corruption layer. You should expect to have many many more resources in your integration domain than you do business objects in your business domain -- Jim Webber