How should a REST URL schema look like for a tree hierarchy?

前端 未结 5 830
Happy的楠姐
Happy的楠姐 2020-12-24 06:04

Let\'s assume that I have stores, shelves in a store, and products on a shelf. So in order to get a list of products on a shelf in a store, I\'d use the following request:

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 06:44

    Since products may be in several stores or several shelves (categories?), I'd have each product have a unique number regardless of its position in the hierarchy. Then use the flat product number. That makes the API more stable when some products are for instance moved in your store.

    In short, don't add unneeded redundancy to your API. To get a shelve list a store ID is enough, for a product list a shelve ID is enough... etc.

提交回复
热议问题