Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better for building an API for my website: MVC or Ado.net data services?

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?

like image 856
Amr Elgarhy Avatar asked Jul 03 '11 20:07

Amr Elgarhy


People also ask

Which is better MVC or Web 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.

Can I use MVC controller as Web API?

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.

What is the difference between MVC and API?

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 .

What is difference between ADO.NET and MVC?

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 ...


3 Answers

Try WCF Web Api. It has got all the cool stuff to create good RESTFul api, and it satisfies all your requirements.

  • You will use basic or some custom http authorization, simple as that.
  • You will expose very basic urls for creating data, validate and return response, trivial.
  • RESTFul means friendly url -s.

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.

like image 74
archil Avatar answered Oct 05 '22 09:10

archil


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.

like image 32
Hector Correa Avatar answered Oct 05 '22 11:10

Hector Correa


Have you considered instead using OpenRasta?

Its clean, ReSTful approach makes it ideally suited to developing web-based APIs in .NET.

like image 45
Ian Nelson Avatar answered Oct 05 '22 10:10

Ian Nelson