Sign in

When designing an API, is it split according to business scenarios or resources?

Argamidon edited in Tue, 06 Sep 2022

I have another users table , There are vendors in the table / photography / Editor, etc . Use the field type to distinguish . But the vendor type users , Each vendor may have more than one vendor_ category .

Now there is a place to search for qualified vendor list_ Category also returns

So I am

提供一个   GET /users api ,通过传递 的 type 来限定为 vendor ,并且加上   vendor_category 信息.


提供一个  GET /vendor api, 只处理 vendor 的信息.
2 Replies
commented on Tue, 06 Sep 2022

Generally, it is still based on the restful interface specification of the business. For example, grapql can also be used by resource

commented on Tue, 06 Sep 2022

You need to consider what are the main elements of the scenario involved in this business.

You need to search for qualified vendor list . The vendor_ Category also returns .

Now that vendor is the subject, why do you think about users?

If it is * * search for users that match vendor, and the vendor_ category 。 Then you can use users as the subject here. In restful design, except for relations, filtering should be solved by using query strings.

Moreover, do not set too many data return results and transfer parameters of an interface, which will increase the difficulty of maintenance in the future. There will inevitably be some unforeseen bugs after business operation.

lock This question has been locked and the reply function has been disabled.