How do I name controllers which are related to multiple entities in REST?

80 Views Asked by At

I want to rename and re-route controllers to make them more "RESTful", and I encountered a problem. Let's say I have ItemsController, the route is api/items. Then I have VersionsController, api/versions. I also have VersionItemsConroller, which is a separate entity. And I also have a controller with this route: api/versions/{versionId:int}/items for, let's say, getting items of specific version (or anything that involves operations with items that are related to specific version), and I don't know how to properly name it, since VersionItemsMappingController seems ugly. Is there a naming convention or some kind of best practice for such cases?

1

There are 1 best solutions below

0
Denis Kiryanov On

Since api/versions/{versionId:int}/items is about getting items of a specific version, it is better to place the appropriate method to the VersionsController.

Thus, the entire structure will look like this:

ItemsController:

  • api/items

VersionsController:

  • api/versions
  • api/versions/{versionId:int}/items

VersionItemsConroller:

  • api/version-tems