I want to implement a Rest service inside my application, which already has different layers (Business Logic Layer, Data Access Layer and Data Model which contains all my entities). I'm gonna using IIS (locally) and Visual Studio.
I created a new project of type ASP.NET -> WEB API.
I have to call the methods of the Business Logic Layer from the controller, so I defined a variable of the Business Logic Type: I'm gonna use it to call the methods.
How should I refer to the resources which REST is gonna use? Should I refer to my Data Model Layer or should I create new classes inside the Models folder in my Rest project (one for each entity)?
What I have tried:
I created an ASP.NET projct of type Web API (empty).
I added an interface which contains all the methods of my Business logic layer.
I created a new controller which implements the interface; inside it, I defined a _businessLogicVariable of the Business Logic class.
I call the methods of the Business Logic by using this variable.
When a method returns void I use [HttpGet], elsewhere I use [HttpPost], e.g I wrote the following to return a User, by posting a username and a password:
[HttpPost]
public User Login(string username, string password) {
return _businessLogic.Login(username, password);
}
User is a new class I created inside the folder Models in my Rest project:
Should I set the
[Route("api/User")]
in the WebApiConfig instead? I mean, should I do that in order to call it from the dataModelLibrary (the external project/layer in the same solution)?