I have a website built with MVC, and now I want to build an API for this website, to let users to use this API to implement different website, web services, plugins and browser extensions.
I went through this article but didn't get yet which to use.
General info about the API I want to build:
The user of the API will have a key user name and password to be able to use the API.
API will let users add content to my DB after validating this data.
API will let users upload images to my server.
API need to have friendly URLs.
Which technology will fit in my case?
Also will help me decide is to know what is the technology behind stackoverflow API?
There are many differences between MVC and Web API, including: We can use the MVC for developing the Web application that replies as both data and views but the Web API is used for generating the HTTP services that replies only as data.
Before I illustrate how an ASP.NET MVC controller can be used as an API or a service, let's recap a few things: Web API controller implements actions that handle GET, POST, PUT and DELETE verbs. Web API framework automatically maps the incoming request to an action based on the incoming requests' HTTP verb.
Asp.Net MVC is used to create web applications that return both views and data but Asp.Net Web API is used to create full-blown HTTP services with an easy and simple way that returns only data, not view. Web API helps to build REST-ful services over the .
Summary. Just as ASP.NET MVC has made building web applications easier, the ADO.NET Entity Framework has made building data connected applications easier. The Entity Framework is not the only ORM tool out there, but it is Microsoft's data access strategy moving forward so it is something that you want to keep an eye on ...
Try WCF Web Api. It has got all the cool stuff to create good RESTFul api, and it satisfies all your requirements.
The general idea is that this library gives you strong manipulation options from the very start of request till its response back. This is the main HTTP api for .NET Framework and WCF and it continues its evolution.
Unless you have a very compelling reason to use WCF, why not just expose your data through the ASP.NET MVC site. You can easily return JSON or any other non-HTML data format that suits your needs from within ASP.NET MVC.
Depending on how similar the interface between your web site and your API need to be you might be able to use your existing controllers/actions or create new ones. In theory if the HTTP request indicates "application/json" you can just return JSON to those requests and be done...but in practice you will probably need to tweak the end points (controllers/actions) to make them friendly to your new consumer (other developers targeting your API)
WCF is very good and feature rich but not everybody is familiar with it. You might incur a learning curve getting a good understanding of it. Again, if there is a very valid reason for it then it's worth it, but from what you are describing you will probably be just as good with plain ASP.NET MVC.
Have you considered instead using OpenRasta?
Its clean, ReSTful approach makes it ideally suited to developing web-based APIs in .NET.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With