I am having a hard time to deal with one particular issue in API design that might be very common. Let me give the concrete example I have: I am writing a RESTFul API for a store and have the situation that there is a /inventory resource to obtain the inventory. The problem is that there are two contexts in which this could happen:
For the actual software and dashboard, the owners want to manage the inventory. There are items that they may set to inactive and should not appear to the public. But nevertheless, they must seem them, so that they can decide do activate, etc. From this perspective /inventory should return the complete inventory.
For the shop frontend, people should see only available items. So the inactive items, or other stuff that is primarily for administration purpose should not be there.
So it seems /inventory should have two behaviors and I don't know what is the correct way to model this in a RESTFul API. I see three options:
This is the one I picked, and I don't like it because I have a feeling it looks unnatural. I have that /inventory is public and returns only what the general public should see. Then /inventory/items is protected and returns everything. So the dashboard called /inventory/items and builds the inventory on the frontend for administration.
The second option is to have two endpoints /admin/inventory and /inventory. I feel it is a bit weird though, because /admin is not a resource. So it is mixing up resource and credentials somehow.
The APIs should be different. This is kind of a realization that there are distinct bounded contexts as in the DDD approach: inventory means different things for the administration of the operation and for the customers. So we should have two distinct APIs: one with endpoint like admin.store.com/inventory that has the full capabilities of editing, etc, and one public.store.com/inventory that has just the queries.
So: when a resource has two distinct behaviors and return schemas, depending on credentials and context, what is the correct way to deal with it in a RESTFul API?
/admin/inventoryis a resource does not mean that a resource/adminneeds to exist