简体   繁体   中英

Internal vs external api methods

I am developing an API and deciding whether I should differentiate external vs internal calls. I was thinking that I would use the same controller class for both internal and external APIs (example: ProductsController.cs (handle the product resource)) with different methods (as different parameters and different return objects, and different authorization) for internal vs external consumption. I am thinking this might become a maintenance nightmare if I want to change api's for internal but not want to change for internal, and it not being obvious which are which. I am thinking that maybe different controller files would be easier for maintainability, but I know they are dealing with the same resource, so I am having an internal fight of which would be the best direction. I also realize that changing of the api would most likely force a change in internal and external apis and thus versioning will also play a role. Any advice would be appreciated.

While they both handle the same resource they do it very differently from what you are saying so it looks like your ProductsController ends up doing two very different things.

To me it's quite obvious that you need to separate them.

You could put them in different namespaces , or even different Areas . If you happen to have some shared logic, you can have that in a base class .

You could create public (external) and private (internal) folders and have a Products controller in both. They could be unrelated or share a base class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM