What is the best way to implement an API in ASP.NET using MVC?

I was a longtime ASP.NET developer in the web form model, and I'm using the new project as an opportunity to get my feet wet using ASP.NET MVC.

An application will need an API so that a group of other applications can communicate with it. I always created the API only using the standard web service before that.

As a side element, I hesitate a little to dive into the REST style to create an API, at least for this particular instance. For this application, most likely, you will need the concept of API version control, and I think that the REST approach, where the API is essentially scattered across all site controllers, is a bit cumbersome in this regard. (But I am not completely against this if there is a good answer to the potential demand potential version.)

So what do you inhabitants say?

+6
web-services asp.net-mvc
source share
2 answers

I agree with Kilhoffer. Try using the Faรงade shell class that inherits from IFacade. In your Facade class, put your code in your web service. Thus, your controllers will simply invoke the facade. The positive side of this is that you can change the โ€œDummyFacadeโ€, which implements the same IFacade interface, which does not actually talk to the web service and simply returns static content. Allows you to perform some unit tests without having to click on a service. Basically the same idea as the repository template.

+7
source share

I would recommend a level of service that can serve clients on the client side or users on the server side. It is even possible to return data in various formats, depending on the consuming subscriber.

+2
source share

All Articles