Should I put my ASP.NET Core API controllers in a special area?

68 Views Asked by At

I've recently started a new project and I'd like to expose an API. Should I put the API controller in a special area (e.g. API) or should I just put them along with the other controllers, or even mix the API action with all the other MVC actions in the controllers?

1

There are 1 best solutions below

0
sommmen On

Aside from numerous answers I could give you, this is something really you can decide. What is logical in your case? What would be more readable?

For example my colleagues like to seperate blocks of code in a technical matter, whilst i like to seperate my systems on functionality.

Just think of yourself being someone that knows nothing of your project, you're going in there for the first time to fix a bug. Where would you expect your code to be placed?

In this case, you can either say okay i'm going to put API stuff in /ApiControllers and your logic for normal controllers in '/controllers'. You could even put controllers in '/controllers' and api controllers in /api/controllers. You can also do somthing like this: 'Users/controllersandUsers/controllers/api`.